I have a very cluttered code, and the current revision is almost complete, meaning all functionalities i wanted for this revision/sprint are done.
Should i finish this revision as it is and refactor it later or should i refactor it right now?
views:
123answers:
7If you're on a deadline and it's something soon, it's probably not a good idea to really make massive changes. If you think the cleanup is manageable, go for it. What I would recommend you do is branch your current code base and do the refactoring in there. Then merge it back. Or you can use the branch as your release branch and refactor in trunk. The longer it stays cluttered, the harder it will be to maintain, so do it sooner than later if you think it's necessary.
If the question regards making something easy to manage and use, and the question is "now or later", the answer is always NOW.
Projects that are "almost done" have a habit of taking longer to finish than anticipated.
Remember: The first 90% of the code takes the first 90% of the time, that last 10% of the code takes the last 90% of the time. =)
There is no "correct" answer for this, it's really a matter of priorities?
- Does the code work?
- How well does it work?
- Are there deadlines?
- Is release more important than quality?
You have to consider all of these questions together. I typically find that refactoring can, especially on larger projects be much more time and effort then you think it may be. You may also be breaking things (this is where unit tests are amazingly helpful).
I typically will strive for release on commercial projects then refactor unless there's major problems with the existing code.
If you are coding to a requirement/api that is stable, there is no reason not to refactor now, if you have time.
If the api/requirements are a moving target, whether to refactor or not is going to be a situational and subjective decision.
BUT.....
If you haven't done so yet, write tests that give wide coverage before refactoring.
I cannot stress this enough.
Do the refactoring as part of your implementation. Have full unit tests so you can refactor without introducing defects.
Refactor now. Procrastinated refactoring is difficult refactoring. Today the code is fresh in your mind and unsullied by tomorrow's changes; it's as ripe as it will ever be for refactoring. Ripe but not yet rotten.