Clean and Refactor Code




Double-check Documentation and Comments

  • Make sure that the documentation comments for each class and method accurately describe the final version of the code you will submit. (If you are using BlueJ, you may find it useful to switch to the Documentation tab to read class and method documentation.)
  • Make sure that the class documentation has your name, the names of anyone you worked with or got help from, and the date of the final version.
  • Provide internal comments for blocks that could be considered "paragraphs" within a method, or for anything that might not be immediately obvious to another human reader. (Or to yourself if you were to come back to this class at a later date.)

Check for Readability

  • Check for good method, parameter, and variable names.
  • Check for indentation. The "Braces Line Up" style (also known as the "Allman style" is more readable than putting open braces on the same line as conditions or loops.
  • Where possible, stating conditions positively is more readable than stating them negatively. When using the ! symbol in negative conditions, put spaces before and after the ! to make it more obvious.
  • Put a blank line (and often a comment) between blocks of code that could be considered different "paragraphs."

Refactoring

  • Long or involved methods might be better broken up into smaller sub-methods.
  • If you have duplicated code, you might be able make a sub-method out of it, or you might be able to simplify your code by having some methods call other methods that already do that work.

Regression Testing

  • Remember to always re-run your test cases after making changes to your code, even small changes to comments, and especially changes to the names and structure in your programs.