Programming Rubrics

— Alex Reinhart and Christopher Genovese

Your homework assignments will be graded as either “Mastered” or “Not yet mastered”. (Challenges may be graded “Sophisticated” as well.) As we grade your assignments, we will look for four key features, described below. For more elaboration on these points, see Best Practices.

Note that TA review is contingent on meeting the basic requirements of the submission. For example, if required tests or scripts are missing, your unit tests fail, or there are significant deficiencies with coding style and organization, the review will stop at noting that issue and you will have used a submission/revision for little gain.

Practices #

A Mastered assignment will usually have

  • Clear and meaningful variable and function names that make it easy to grasp their purposes
  • Consistent indentation and formatting of code blocks to make the structure of the code visible
  • Minimal use of global variables
  • Named constants rather than “magic numbers” (hard-coded numbers embedded in the code)
  • Documentation and comments that describe the purpose of the code and why it does things, rather than stating obvious facts about what the code is doing

There are many style guides that prescribe naming rules and formatting practices that are meant to make code more readable. We recommend:

R
The tidyverse style guide.
Python
The PEP 8 Style Guide, which is almost universally used by all Python users. The PEP 257 Docstring Conventions describe how to format Python docstrings to document functions and classes.

Design #

A Mastered assignment will usually have

  • Small, self-contained functions that perform well-defined tasks and are easy to test
  • Classes that are encapsulated and are used through specific methods, not by mutating their internal variables
  • Common code factored out into reusable functions instead of repeated several times
  • Flexibility to be used in different ways
  • Weak coupling between components (like classes and functions), which only have to know the interface of other components, not how they work internally

Representations, Algorithms, and Data Structures #

A Mastered assignment will

  • Use an algorithm appropriately chosen for the problem, with theoretical performance close to the optimum that’s realistic for the expected data/problem size
  • Use a data structure appropriately chosen for the problem that makes the most common operations needed fast and easy
  • Represent the problem to be solved in a simple way that makes it easier to solve the problem

Correctness, Elegance, and Performance #

A Mastered assignment will usually have

  • Thorough unit testing that checks all important functions and ensure they are correct
  • An elegant approach that solves the problem in a reasonably simple way, without unnecessary complications
  • Enough speed to solve realistically large inputs in a reasonable time. (Previously we were talking about theoretical efficiency of the algorithms and data structures, here we’re talking about practical real-world performance.)