up: Programming

Practical refactoring

Practical Refactoring - How to clean code in many small steps

Things to remove:

  • Clutter

    • ”Anything in your code that does not add value”
      • Redundant comments
      • Dead code
      • Unneccesary code
    • That makes everything else harder to understand.
  • Complexity

    • Bad names
    • Long methods
      • Every method should fit on a screen
      • Find the “seams”1, and break it into new methods
      • These should be Well-named methods.
    • Deep conditionals
    • Magic numbers/strings
      • Magic numbers, if required, should be in a seperate settings file.
  • Cleverness

    • Make it clear. Make it elegant. Make it easy to read. Clever is going to bite you later.
    • If it needs a comment, it’s clever.
  • Duplication

    • Extract repeated statements into methods


  1. Usually curly-braches, like if expressions. This is similar to the Extract Conditional Pattern.