Most organizations have specific guidelines or standards about how work is to be performed, completed, tested and submitted. This page describes the standards for SDEV 140. It covers standards for configuring your Python programs , how to comment code, and how your assignments should be named and submitted.
In some editors,such as (Notepad++), your code must be saved as a file before it can be executed and tested. So it may be helpful at that point to name it so it can be submitted for the assignment.
Programs should be named in the following format:
Notice that the filename contains NO spaces or hyphens, and that your lastname comes before your first name or initial. The file extension should be ".py". Both IDLE and Notepad++ work with .py files. (If your editor defaults to a different file extension and cannot save files using a .py extension, let the instructor know.)
All programs should have a standard header with course, author, date, program name and purpose, similar to the following:
Notice that there is a space after the hash mark that starts each comment line.
Various coding languages use different conventions for things like variable naming. A convention is a commonly accepted way of doing something, such as naming files or variables in a coding language. Naming styles have their own names, such as camel case, Pascal case, kebob case and snake case. You can read more about these common naming styles here.
For this course, please use either snake case OR Pascal case. Once you decide which you prefer, be consistent and use it all the time. Do not use different naming styles in the same program. (The exception is that the Python convention for constants is UPPERCASE. More on that later.)
All programs should include comments, in addition to the header. Comments help the reader understand the purpose of the code ,without having to read through it in detail.
It is not necessary to comment every line. But comments should be provided for sections or groups of code that have a similar purpose.
games = 3
total_score = 465
average = total_score / games
# display results
Please display a banner when your program runs so it shows the program name or purpose, and your name or initials. For example:
Advanced Standards M02 and after
These standards will be "enforced" starting in M02. In other words, points will be subracted for each program where the standards are not met.
- do not use literals (except 0); use global variables instead
- constants (global variables) should be named in all uppercase
- comment space: place one space after the # character
- number formatting: if not otherwise specified, decimals should always be 2 places (.2f)
- do not automatically convert input values: more below
Advanced Standards: M03 and after
These standards will be "enforced" starting in M03. In other words, points will be subracted for each program where the standards are not met.
- The main program should not perform any significant work (processing). Except for printing the banner, all other work should be contained in functions (methods).
- Global variables should be minimized. Constants are the except and should be global variables. Most other variables should be scoped locally in each method.
- Methods should be as short as practical, and should primary perform a single task (SRP: single-responsibility principle)
- All user input should be validated (see do not automatically convert input values, above)