Software Development
Blogs and Discussion
developer.*
Books Articles Blogs Subscribe d.* Gear About Home

Refactor-itis

I have an urgent need to talk about a disease which is a threat to the health of the software we create: "refactor-itis".

Martin Fowler's book on refactoring is a valuable piece, because it describes both phenomenea and cure. It also explains that refactoring is sometimes required to get to a stable code base. However, ever since his book has appeared a lot of people have been misusing the word on a frequent basis.

Martin Fowler's definition is the following:

"Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior"

In its purest form, it's altering the internal structure without changing the external behaviour. Most often I hear the word 'refactoring' when people want to redesign a piece of software, when they want to write a whole new implementation, ... . As refactoring has the following connotation : 'it is a maintenance effort we cannot really escape from', it often gets accepted because it is well hidden under the cloak of 'refactoring'.

If it were not hidden under this cloak, people would have to answer more questions such as "why is this necessary", "what are the risks",...

I have heard the phrase "I've refactored the interface" being used a couple of times. This is actually in total contradiction with the real meaning of the word.

The problem is ofcourse : How we can cure this decease?

To do that, we should detect the symptoms : we should be triggered when somebody uses the word 'refactoring'. Instead of just accepting it, we should ask through in order to get an idea of the real nature of his/her request. To be able to do this, you should come to a situation where 'refactoring' ideas get announced prior to getting executed (for example in a short meeting or in a short stand-up meeting. Definitely not by e-mail but rather in face-to-face meetings).

The actual cure is that you need some form of sensibilisation of the associated risks of so-called 'refactoring' efforts together with a gatekeeper (or gatekeeper team) which will protect the system from unnecessary rework. I believe that creating business-awareness is a good way to tackle the decease : people should realise what the impact can be on the business. When they do, they'll already have a difficult time in convincing theirselves of the neccessity.

Also, you can more easily decrease the chance that people catch 'refactoritis' if there's enough work on their plate : When you have a tight schedule, people will automatically avoid unnecessary work (this is the human nature).

About the refactoring of an

About the refactoring of an interface: this is totally acceptable (and according to the definition of Fowler) if the behaviour of the system as a whole does not change.
It all depends on the point of view you have: you can refactor a single component (which means the interface will not change), or you can refactor e.g. the interaction between components (which means the interfaces may change, but the system as a whole will not).

On a more general note: refactoring is a natural part of the coding process. However it should be done early on, to come to a clean implementation as soon as possible.
If the code is left in a messy state, the refactoring will be required much later on (when the bugs start coming in), and at this point it will become much more expensive (and it will introduce more risks).
So: write good code in the first place, and the need for refactoring will be diminished.

Of course: refactoring just for the fun of it is never acceptable (at least not in a professional environment).

Refactoring and reuse

I agree with the guest's view that an interface may be refactored, as long as it does not alter the external system behavior. Of course what is considered 'system' and 'external' may differ if there is fine grain reuse across systems. For example if the said interface is reused for another system, then altering it affects a certain 'external' behaviour of the system. my 2 cents...

Refactoring with sense

I totally agree with your statement that refactoring for fun is not acceptable in a professional environment. However, I've seen people working this way systematically : constantly changing interfaces under the cloak of 'refactoring' instead of taking one step back and checking why it needs constant revising without requirement changes. The root cause (in this example) was that the developer simply didn't think things through.

Damith gave a good response on the refactoring of interfaces : People are not always fully aware that they are not the only consumer of a certain interface.

For example, why is Microsoft's Visual Studio API breaking some of its interfaces every time a new version comes out ? The reason is simple: there's not enough emphasis on refactoring with sense.

Mario.

Refactoring for quality

I do not see anything wrong with refactoring,if it is done for a better quality. After all, we are living in a progressive era. Things are progressing and changing everyday at fast pace. It would be inappropriate to resist the changes.

Refactoring Outside of a Vacuum

Hi, John, thanks for your comments. I agree with you that refactoring should not be resisted simply because of fear of change. I think the interesting part of the "should I refactor this?" question is the larger picture--as in the example above, if we refactor a public interface without considering the "contract" implicit in that interface, then we can break other people's code in the process. I would say also there is a general risk consideration: how complicated and intertwined is the code you are looking to refactor, and do you have the time and resources to ensure that the code will still behave the same after you're done? In a production maintenance situation or under schedule pressure, if the risks outweigh the rewards then the prudent thing might be to simply add some good comments to the code rather than refactor it. That's not resistence to change, just professional pragmatism.

Anyway, I don't mean to come off as lecturing you. I agree with your point: if better quality will result, go for it. But like those physics problems where the formulas only work if you assume the absence of gravitational pull or friction, sometimes reality gets in the way.

Dan

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Recent comments

User login

About our advertising.

Atom Feed

developer.* Blogs also has an Atom feed, located at this url.

Click here for more information about Atom.

A Jolt Award Finalist
Software Creativity 2.0
Foreword by Tom DeMarco

Recent Posters

Based on most recent 60 days, sorted by # of posts and name.

Google
Web developer.*

Who's online

There are currently 0 users and 20 guests online.

Syndicate

Syndicate content
All views expressed by authors, bloggers, and commentors are their own and do not necessarily reflect the views of developer.* or its proprietors.
Click to read the Copyright Notice.

All content copyright ©2000-2005 by the individual specified authors (and where not specified, copyright by Read Media, LLC). Reprint or redistribute only with written permission from the author and/or developer.*.

www.developerdotstar.com