Friday, February 26, 2010

Refactoring vs business

In our current project the business officially hates the word refactoring. And right so.
Today every attempt to "improve" the code is called refactoring. However, the original term, as introduced by Martin Fowler's book "Refactoring", ment something different. It ment something much more narrowed than just improving the code.

Refactoring means improving the code in tiny and clearly defined steps, while always keeping the original functionality.

First of all, most of the projects i have seen so far, do not have enough test coverage. So you can't really be sure, if the functionality remains intact. Secondly, a lot of people don't even bother to add new tests while they refactor. Which means they don't even know, what functionality is there after the refactoring. And last but not least, the approach of tiny little steps, hasn't really made it into the devs mind at all.

The outcome of this adhoc "refactoring" doesn't come unexpected. Most likely you will see many things breaking or even missing after the refactoring. And this makes the business crazy. They don't like to pay somebody for breaking existung features.

So what can we do about it? First of all, don't use the word refactoring if you mean a plain rewrite. Secondly, avoid the word refactoring when talking to the business. They don't really understand what quality of code can buy them. This way you don't have to use the word refactoring when you talk to the business.
Imho we should be refactoring all the time, if we see some smell in the code. However, newcomers might see smells where oldtimers don't. So, before you refactor, talk with your fellow developers about it. Last but not least, if you refactor, make sure you do it right. Don't leave out the tests. They might not cover everything, but they should give you a good baseline of confidence in your code.

I promise, if we all follow these practices, one day, we will see the business beeing happy about refactoring :) At the latest, if they ask you for new features and you can build and integrate them easily without breaking things.

No comments:

Post a Comment