Code should be readable and efficient.
Avoid magic numbers (literal primitive numbers) by using variables with meaningful names.
Write functions that are small and do one thing.
Write test cases before writing any code.
Class attributes are for representing an object of a class, not a convenient way to pass information between functions.
All lines should be less than 80 characters (the default width of an Emacs window). The best way to ensure that all lines of code are less than 80 characters is to write simple statements that do only one thing. When a line must span multiple lines:
break after commas.
break before operators.
prefer higher level breaks.
Functions should be 40 lines or less, including comments.
Indent with spaces (the default behavior for Emacs), not with tabs.
Files should have a block comment at the top with the author and purpose of the file.
All functions should have a block comment above them that includes:
There should be only one variable declaration per line .
Initialize variables on the same line as they are declared, if possible.
Declare variables at the beginning of the block of code in which they will be used.
Lines should not have more than one statement.
Use only one assignment operator per statement.
Functions should have only one return statement (if any) and it should be the last statement in the function.
Blank lines should be used to separate related sections of code and should be preceded by a comment explaining the section of code.
Functions should be separated by blank lines.
Binary operators (+, -, *, etc.) should be separated from their operands by spaces (except for the . operator).
Unary operators (-, ++, etc.) should not be separated from their operand by a space.
Argument lists should have spaces after commas.
Names for variables, functions, and classes should be meaningful. Common abbreviations are OK (avg, max, etc.) but single character names and acronyms should be avoided.
Function names should start with verbs and describe what the function does.
Class names should be nouns and describe what the class represents.
Default parameters and named arguments break the spaces around binary operator rule.
Do not use from module_name import *. Instead replace the * with what specifically to import from the module.