Skip to main content

Guidelines for Code Quality

In addition to the correctness of your program, you will be graded based on the quality of your code. Our assessment will consider the following elements:

Documentation

Code is well documented and written in a way that makes it easy to comprehend (see this guide to documenting your code and the official docstring conventions):

  • Docstring comments are provided for every function (unless the assignment explicitly states otherwise)
  • Comments throughout code make code easier to understand for the reader (e.g., where needed to explain something tricky)
  • Function, variable, and class names are descriptive

Style

You follow best practices for style in your code (see the PEP8 Style Guide):

  • Whitespace is used appropriately to:
    • Logically separate pieces of your algorithm
    • Make expressions more readable
    • Separate function definitions with a single blank line between
  • Consistent style is used for variable, class, and function names
    • snake_case is usually used in Python for variables and functions
  • Line length is less than 80 characters
  • “Commented out” code that is not functional is removed
  • “TODO” and “Fill in here” comments are removed before submission

Design

Your code is written efficiently and appropriately uses programming constructs:

  • Variables are used effectively and help to avoid repetition
  • Named constants are used appropriately to enable modification of constants
  • All branches of conditionals are reachable
  • Brevity: you should not copy-paste code within your program if at all possible!
    • Code is separated into meaningful functions
    • Loops are used when you are doing the same thing multiple times
      • break and continue are used sparingly
  • Code shows good understanding of programming constructs
  • Appropriate use of data structures