Refactoring in Real Life

pipes-before1

While upgrading my kitchen last weekend I encountered a great opportunity to simplify the plumbing. The experience resonated with how I think about software projects.

pipes-after1

I had to make room for an integrated dishwasher beside the sink. It needed to be completely flush with the wall. The pipes sprawled half the width of the worktop, mostly completely redundant. Previous quick fixes and badly thought out additions left it harder to understand, and more time consuming to change. I managed to remove meters of pipe and dozens of joins, without changing external behaviour. Others before me skipped the oppurtunity, costing me extra time to make my change.

pipes-pile1

The cardinal rule of software evolution is to improve internal quality when making changes. The principle being: change is inevitable, and messy code is harder to change, so reduce the cost of change by a constant attention to code quality.

The messy plumbing only cost me a few hours work. I won’t look at it again for 10 years. With software your ability to change is your only lifeline. Plan for change. Your good decisions today, may be bad decisions tomorrow, make them quickly and change when you know better.


6 Comments

Amen to that. I have to rip the nested tables out of a site and replace it with proper semantic xhtml and I’m going to enjoy doing it too.

Posted by Matt Finucane at 6:15 pm on 24 August, 2009.


So true. Just reading “Pragmatic Programmer” by Andrew Hunt and David Thomas which I recommend. They give some good examples that crosses all programming languages to help you keep and maintain your code base.

I know some decisions I made 5 years ago with 1time I cringe at now but as we add features I allocate time to improving the framework and re-plumbing. It benefits in the long run.

There is a delicate balance here where some times you have to say its “good enough” code and continue but over time you still move forward with the system as well as the features.

Posted by Derek Organ at 11:23 am on 25 August, 2009.


Derek, Good book indeed.

Here’s an interesting blog post about deciding/justifying when to pay off technical debt - http://www.codesqueeze.com/refinance-your-technical-debt-just-like-your-mortgage/. It helps you put numbers on the ‘good enough’ decision.

I’m guilty of rarely even communicating with project stakeholders that I have or intend to ‘pay off some debt’. I think I get away with this by taking a little and often approach, 5 minutes here or there as I’m re-reading some code, rather than a, stop the world, we are ‘refactoring’ this week approach.

Posted by Darragh Curran at 9:37 am on 26 August, 2009.


Interesting first post Darragh. Has me wondering what elements in my home / life need some refactoring. I may need to refactor my cd collection at some point, a classic example of sheer bloatware

Posted by Ed Benton at 1:04 pm on 2 September, 2009.


Interesting analogy, but how often do we get to work purely for ourselves?

Imagine for a moment that you had asked a professional plumber to do the work -would you have been happy for him to charge you to spend an hour or two ‘tidying up’ when five minutes would have given you something that worked?

Posted by Mike at 7:23 pm on 29 September, 2009.


Good point Mike.

In this particular case, I needed to do extra work to achieve my goal, I could have cut a few corners, but as you’ve hinted, sometimes you’ll have different priorities when working for yourself. Perhaps perfection over pragmatism.

I hope a plumber would explain the trade offs; How a bit of extra work now is worth it if…, or is needed because…, or is not worth it because…

In software, it’s very rare that a ‘quick fix’ has a overall lower cost than a ‘good’ fix. And good people take less effort to do the right thing than a wrong thing. Mind you, a ’slow’ fix aka gold-plating ain’t right either.

Your summary of two hours extra to tidy up, vs 5 minutes to just get it done, reminds me of something I squirm when I hear, “We’re spending next week refactoring the code base”, a sure indication a project is out of hand; we have lost the ability to add value, and are instead paying off debts.

Thanks again for the comment, it’s sure something I could chat about for hours, but I’m onto my next home improvement project…..

Posted by Darragh Curran at 8:17 pm on 29 September, 2009.


Post a Comment

We do web apps. E-mail e-mail address. Phone us at +353 1 672 9762. Post to 51 Wellington Quay, Dublin 2, Ireland.