Do you ever need to explain why refactoring is a good idea to your clients or your boss? Not really geting through to a non-techy? This explanation shoudl help you justify refactoring.

I am sure we all have been there – you wrote an amazing piece of software at the time, fulfilling all the clients needs, bug free and so on and so forth. However two years later it more work comes along and you suddenly fin yourself in dire need of refactoring.

Now many clients (or bosses as a matter of fact) will be quite resilient to the idea. Trying to look at this from their perspective you can easily see where the problem lies. They spent money and time on a solution and now it seems you want to go and throw out all that has been done on some whim, or just for the joy of starting with a blank canvas. At least so it seems.

There are two things you need to explain about refactoring to get your point across. Obviously we start with an assumption here that it actually is the right thing to do, and not just a developers fondness for reinventing the wheel speaking…

The hairdresser analogy

Refactoring is a bit like getting a new hair cut. Where the hair style is your code and the hair is the concept you are trying to implement. Thus even though you might not leave a line of the old code the “hair” is still there to be worked on.

There may be many reasons why to refactor and the old code definitely has done it’s job at some point. Very often it is the lessons learned and limitations of the old implementation that do lead to the need for new code. It is a bit like cutting of too long hair to strengthen it and maybe for practical reasons.

This however only helps explain what refactoring is. It might not be the best example about why you need it, or why you haven’t gotten the hair-style right the first time round.

The garden analogy

I would like you to think about a garden. Let us imagine a small plot behind your lovely house. You can plant flowers, and bushes and trees, etc. and say you decided to cover up the back wall with a line of shrubs – they do cover the ugly wire fence nicely.

Now fast-forward 5 years later. It turns out you have an amazing deal on the plot of land just behind your own garden. You cannot build on it, but it would make your small green space a lot bigger. It’s an opportunity not to be missed. So you go ahead with that new feature, I mean extra land.

There is just a slight problem – your perfectly usable garden has shrubs just where the new plot meets your existing one. Oh, and they’re huge now – you can imagine what 5 years can do to a fast growing shrub… I mean you could just carve a whole and go through it but that is not an elegant solution.

Your original garden layout was not planned for the extension and there is nothing wrong in that. You do not have to bulldoze the whole of the old space, but obviously the shrubs have to go. If you plan carefully you might be able to replant them somewhere, however that is a whole different story.