I'm writing to make sure I fully understand the guidance on refactoring, as I'm currently reconciling two points that seem a bit contradictory.
On one hand, I understood the advice that if working on a small portion (say, 10-20%) of a large, existing codebase, one should avoid refactoring only that specific section. The rationale was that mixing significantly refactored code with untouched legacy code can lead to problems, implying that if refactoring is undertaken in that area, it should ideally encompass the entire codebase.
On the other hand, there's the principle of "make it a little better each time." The example provided was performing some cleanup on a legacy API when creating a new function that interacts with it. This approach seems to encourage incremental improvements and modernization, acknowledging that dedicating resources to refactor an entire codebase at once isn't always practical.
Could you perhaps elaborate on how to balance these two ideas? I'm trying to understand the threshold or context for when incremental cleanup is appropriate versus when touching code might necessitate a much larger refactoring scope (or perhaps avoiding isolated refactoring altogether).
Great question! The main factor to consider here is the intensity of the change. The thought process here is as follows: