In this course, you will be marked not only on whether your code works, but also on style. Here are some guidelines:
Use Python style conventions for your function and variable names (pothole case: lowercase letters with words separated by underscores (_) to improve readability).
Choose good names for your functions and variables. For
example, num_bright_spots
is more helpful and
readable than nbs
.
Use a tab width of 4 (Wingware's default), if you use tabs at all. The best way to make sure your program will be formatted correctly is never to mix spaces and tabs -- use only tabs, or only spaces.
Put a blank space before and after every operator. For example, the first line below is good but the second line is not:
b = 3 > x and 4 - 5 < 32
b= 3>x and 4-5<32
Write a docstring
comment for each function.
Your function comments must mention what, if anything, the function returns, and the purpose of each parameter. The comment must be grammatically correct.
Put a blank line after every docstring
comment.
Each line must be less than 80 characters long
including tabs and spaces. You should break up long
lines using \
.
In Wing, you can find out what column you are in by looking in the lower left-hand corner.
Complicated bits of code inside functions should have comments describing their purpose. For example, a loop that swaps the red and blue values in the pixels of a picture might have this as a comment:
# Swap the values of the red and blue components of every pixel.