November 23, 2010
Undo-ability Is The KeyAn abortive attempt at a fairly long-winded refactoring serves as a reminder of the importance of undo-ability in day-to-day coding.
One of the habits I encourage when coaching folk in refactoring is to check your code in at every refactoring milestone. It's a bit like saving your place in a computer game after overcoming an obstacle.
I was just trying out a sequence of refactorings to get rid of a conditional in a high-level module and replace it with polymorphism, and a little fiddly bit at the end turned out to be too fiddly. indeed, it was a dead end. I'd taken a wrong turn about 5 or 6 refactorings in and found myself unable to CTRL+Z my way out.
Luckily I run local source control on my laptop and make a point of checking in after I meet a short-term goal, like eliminating a code smell.
Undo-ability is one of the most important factors in software development. The ability to go back and try again is paramount to experimentation, which is what coding and refactoring are at heart. We never know absolutely for sure that what we're doing is going to work. So the ability to safely and cleanly undo it is something I cannot live without. It's one reason why I try to use automated refactorings whenever possible and why I find that source control is not just useful for working in teams.
Undo-ability is also very handy on a larger scale. The ability to cleanly and quickly roll back a software release with no ill effects is vital in a world where operational continuity is critical to businesses and organisations.
Knowing that we've broken something is one thing. But knowing that undoing the damage will be difficult and time-consuming makes it much, much worse. Having easy undo-ability massively reduces the cost of mistakes, and this is fundamental to any healthy process of innvation, which is, let's face it, trial and error a lot of the time.
Anyway, I'm taking a break to clear my head and in a few minutes I'll get another clean copy of the code and try again. I'm glad I have that luxury.
For details of the upcoming Refactoring Master Class and other Codemanship courses in London in Jan-Feb 2011, visit http://www.codemanship.co.uk/training.html
Posted 10 years, 4 months ago on November 23, 2010