Refactoring must be done systematically - Thu, Mar 17, 2022
Refactoring must be done systematically
“Refactoring, if not done properly, can set you back days, even weeks. And refactoring becomes even riskier when practiced informally or ad hoc … To avoid digging your own grave, refactoring must be done systematically.” (Refactoring, Martin Fowler et al.)
In essence this means that once you start refactoring on an ad hoc basis (e.g. as a side effect when implementing a new feature), chances are that you dig deeper and deeper changing more and more code in the process without having the bigger picture on your mind.
This may lead to unrelated code changes and inconsistencies in the code in particular when done by different people without proper reviews.\
This principle is especially important when applying the The Boy Scout Rule :
“Always leave the campground cleaner than you found it.” (Clean code, Robert C. Martin)
Why is that ? The key term here is
cleaner. Cleaner is not a tangible term any it may very well be up to the individual to decided what
cleaner actually means. Which is perfectly alright but might lead to the above mentioned “unrelated code changes”.
When a team is having an overall refactoring strategy / golas, team members should be aware of the big picture of this refactoring strategy when applying the “Boy scout rule”. That way following the boy scout rule on a daily basis has the benefit of implicitly helping achieve the overall refactoring goals.