CS 115 Project 1 Style Grading Sheet


You can test most of the items in the "Formatting" section by copying your program to the cwolf server, logging into cwolf and navigating to the correct directory, and running the following command. Fill in the name of your file where indicated:

~srivoire/bin/python_style_check.sh yourprogram

Pay attention to any output this program prints. If it doesn't produce any output, then you're in good shape.

The error codes refer to the Python PEP 8 style guide, which is the basis of these rules.

Here is how to read an error message from this command:

proj1.py:10:1: W293 blank line contains whitespace

^

The "10:1" means that the error occurred on line 10, column 1 of your source code file. You can reopen emacs directly to this line by using a "+10" (since you want line 10):

emacs +10 proj1.py

The "W293" refers to the PEP8 rule that your code violates. In this example, a "blank" line in the source code actually has invisible tabs or spaces.

Finally, the error message will show the offending line of your code, and put a

^
symbol underneath the specific error. Since this source code had extra space in a "blank" line, it printed a blank line and marked the beginning of that line.


Programming Style (30 points)

Docstring (4 points)

There should be a docstring at the top of your submitted file with the following information:

1 pt.Your name (first and last)
1 pt.The course and assignment (e.g. CS 115 Project 1)
2 pts.A brief description of what the program does

Documentation (6 points)

Not counting the docstring, your program should contain at least three comments explaining aspects of your code that are potentially tricky for a person reading it to understand. You should assume that the person understands what Python syntax means but may not understand why you are doing what you are doing.

6 pts.You have at least 3 useful comments (2 points each)

Variables (4 points)

4 pts.Variables have helpful names that indicate what kind of information they contain.

The most common ways to lose points are:

Algorithm (3 points)

3 pts.Your algorithm is reasonably efficient, with no wasted computation or unused variables.

Formatting (10 points)

These guidelines come from the Python PEP 8 style guide.

Pay attention to any squiggly underlines you see in Pycharm! They often indicate violations of PEP8. You can hover the mouse over each squiggle to see an explanation of the problem.

3 pts. Operators and spacing:
  • Commas: There is no space before a comma and one space after.
    Example: print(a, b)
  • Mathematical and relational operators (+, -, <=, etc.) are always preceded and followed by a single space.
    Example: a = b + c
  • There are no extra spaces after a left parenthesis or bracket, or before a right parenthesis or bracket. See the print example above.
1 pt. Indentation and whitespace:
  • Indentation: You always indent by a multiple of 4 spaces.
  • Your lines do not have trailing whitespace (extra space after the last printable character).
2 pts. Blank lines:
  • You use two blank lines before def main() and two blank lines before the final call to main().
  • You use blank lines to break up your code where appropriate, but do not use more than one blank line in a row, except as described above.
2 pts. Comments:
  • There is always a single space after the # character.
  • A comment at the end of a line of code (as opposed to a line by itself) has two spaces before the # character. Example:
    a = b + c  # sample comment
2 pts. Line length: Your lines all have fewer than 80 characters. You can have statements that are longer, but you must break them across multiple lines to increase readability. Ask the instructors if you need help breaking up long lines.

Program structure (3 points)

All or nothing: your code should define a main function and then call that function, just like our programs do in class and lab. Other than library imports, the docstring, and the final call to main(), you should not have any stray code outside a function definition.

How to check for this: look along the left margin of your source code. You should only see your initial docstring, import statements, def statements, and the final call to main(). Anything else, and you lose these three points.

Catchall

For students using language features that were not covered in class, up to 5 points may be taken off if the principles of programming style are not adhered to when using these features. If you have any questions about what this means, ASK!