Continuous addition of code to the existing code base can make it unreadable and it needs re factoring and redesigning. There is no doubt regarding that. To redesign the code every time you add a functionality is not quite possible. Sometimes you allow small fixes to get in the existing code as patch with a promise that you will redesign it once more changes drop in.
So, how to manage the continuous inflow of sporadic changes here and there.
There is a trade off between the effort applied to redesign the code every time a functionality is added and the gain obtained from it. You cannot afford to spend twenty five percent of sprint in redesigning the application every time you inject something new.
But, the continuous changes will spoil the code base soon. So, to save the code from rottening, keep the readability of the code intact. If the code is readable, then its easy to work upon, as well as re factor.
Commonly used re factoring techniques to maintain the readability of the code:
- Keep methods small.
- Give meaningful names to methods and variables.
- Each method should be doing only one thing.
- Try to subclass classes for new functionality (if possible), instead of adding methods to the same class.
- Try to extract classes from classes having lots of code.
- Try to maintain the abstraction in classes.
- All classes should be concerned with only one responsibility.
These are also the basics of clean code. Nowadays the re factoring is also very easy with help of IDE’s. In eclipse, Alt+Shift+M ( for putting a number of lines in a method) and Alt+Shift+R (for re factoring a variable name at all places of its occurrence) will be your best friends in re factoring.
So, if you maintain the readability and abstraction of the code. Then even if you don’t redesign it every now and then in the best possible way, it will be easy to work upon. And the time when you start re factoring and redesigning, it will be far easier to do than it would have been without all these.
No comments:
Post a Comment