Meditation is a stress-busting practice recommended by doctors all around the world. When we meditate, we train our minds to achieve relaxation. Though there are a number of ways in which meditation brings about relaxation, it typically involves an internal effort whereby our conscious is made to reflect on issues, feelings, and emotions for the purpose of easing internal hardships and relieving stress. At the end of the session, our exterior might look the same, but our mental well-being has experienced a mini-makeover.
Code refactoring is a lot like meditation. Refactoring involves restructuring existing code without changing its external look. When a developer refactors code, he or she carefully studies its internal structure, searching for ways in which to simplify it. The external behavior of the code remains the same, but the developer has made the code easier to read, maintain, and work with. In some cases, refactoring can also uncover hidden bugs.
Now what about frequency? Well, research indicates that regular meditation has positive effects on a number of ailments including depression, anxiety, sleep problems, heart disease, and high blood pressure. Of course, there are no studies on the long-term benefits of regular code refactoring (not that I know of!), but its safe to assume that they’re numerous. And just like how you wouldn’t cram all your meditation for the year into one weekend, you shouldn’t try to cram code refactoring at random and sparse intervals.
That’s why I believe that refactoring should be done on a continuous basis. By getting into the habit of refactoring when and where you need it, you’ll find that it’s easier to work with over the long-haul. By cleaning up today’s code, tomorrow’s will be easier to develop. And like with meditation, you might even find your stress levels will be reduced as your code is always being made more manageable.
Don’t get bogged down by the unnecessarily complex code. Let your code find inner peace today by embracing the art of continuous refactoring.