Nano Refactoring — Leave the campground cleaner than you found it

The Boy Scouts of America have a simple rule — ‘Leave the campground cleaner than you found it’*.

Applying this to context of software development especially for a large complex legacy code base, what essentially it means when you get to modifying a legacy code base for a specific bug fix, can we do some quick refactoring around the code you are modifying. I call this as ‘Nano Refactoring’.

The campground for Nano Refactoring is the ‘function’ being modified for specific bug fix. The type of clean up done under Nano Refactoring must fit into ‘Low Effort & Low Risk’ category such as

  • Appropriate commenting (add/remove/modify).
  • Rename any local variables per guidelines.
  • Removal of duplicate variables etc.
  • Additional assert, try catch for better error handling.
  • These nano refactoring efforts looked in isolation can be dismissed as trivial but the aggregation of these marginal gains can be significant in the long run. If each function/class/module was cleaned up by 1% every day, at the end of one year you would have 37% of your code base cleaned up almost with no addition efforts or risks.

    Incremental improvement

    + Boy Scouts rule above from Robert C Martin’s book Clean Code
    ++ The Power of Tiny Gains from James Clears book Atomic Habits

    Software Engineering Refactoring

    Clicky