Code refactoring is a programming technique that involves rewriting code in a way that improves its readability or simplifies its structure without changing its results. Thus refactoring is mainly about improving code maintainability. Code smells is a term coined by Kent Beck, and refers to certain attributes of written code that suggest it should be refactored.
There is another advantage to refactoring beyond maintainability, and it relates to development decisions. In software development, there is a tendency to over-anticipate what would be needed in the future. Functions with many parameters get written, classes get many methods to accommodate possible use-cases and projects get classes that encapsulate speculative possible future needs. A lot of code is written on the basis of what could be possibly needed next.
The reason this is happening is that programmers are reluctant to touch code that has already been written and is working properly. By using refactoring, programmers can maintain a better balance between operational and flexible code, writing code that works now and refactor when its needed. This can save a lot of development time, as most of the anticipated use-cases never come to pass (as is the case when trying to predict the future). I am not suggesting avoiding planning ahead when deciding on architecture, however when implementing it’s often better to settle on ‘good enough’ rather than ‘perfect’ (which might be unachievable).
To know when the next article is published, please subscribe to new articles using your Email below or follow me on Twitter.