When you should refactor
At this point, we have a clear understanding of what refactoring is and why it holds such significant importance or, I would even go as far as to say, it is crucial in our daily work. You may be wondering when is the appropriate time to engage in this activity. There are several factors to consider when deciding on the timing of refactoring. It is no secret that refactoring can be time-consuming, so how can we effectively incorporate it into our workflow? When is the optimal time to execute this activity?
Let me start with some fundamental advice based on our experience: it’s always a good idea to do some minor refactoring whenever you have the chance, even if it means integrating it into your current task. For example, while running tests or performing static code analysis, you might come across a variable named x. That name doesn’t convey much meaning, does it? So, you’ll spend some time trying to figure out what that variable represents...