General Coding Guidelines for all Languages
- Code Should be Easy to Read
- Use whitespace for readability
- Use a naming standard
- Consistent intentation and formatting
- Write API docs in comments for classes and public methods. For Java use Javadoc, for Python use a standard docstring format (Python, Google, or SciPy standard).
- Write comments where needed to explain the purpose of code.
- Don’t Repeat Yourself (DRY) - avoid duplicate code and duplicate logic
- Avoid magic numbers in code
- Avoid string literals in code for things that represent specific values
- One purpose for each variable
- Each method does only one thing
- Use descriptive names and avoid abbreviations
- Avoid global variables
- Return results, don’t print them
- Fail fast (return error or throw exception when data or params are invalid)
- Handle or propagate all exceptions that might reasonably occur
These guidelines are similar to the style standard in the MITx course Software Construction in Java,
Code Review
Professional developers (and serious volunteer developers) do code reviews!
You should review all your code, repeatedly.
Code Review available on edx.org.