Wednesday, April 28, 2004

Don’t Refactor and Enhance at the Same Time

Last night at my "Introduction to Refactoring" presentation, I received a bunch of blank stares the first few times I said that you aren’t supposed to refactor and enhance at the same time. Eventually, it dawned on me that I was being imprecise in my definition of the word "enhance." After all, refactoring is itself a form of enhancement -- you are improving the design when you refactor. So, what I meant by "enhance" is adding functionality from the user’s (customer’s) point of view. I don’t know where I picked up that terminology. Maybe it was a culture thing where I’ve been working. Do other people use the term "enhance" that way?

Anyway, the bottom line is you aren't truly doing refactoring unless
  1. you isolate the refactoring activities from the feature-adding activities,
  2. before you apply a refactoring you have an automated unit test that puts the existing functionality through its paces, and
  3. the exact same unit test runs cleanly before and after the refactoring is applied.
Note that it’s okay if the unit test has to be tweaked to conform to new method signatures and whatnot, but you can’t change anything that has to do with what the unit test is trying to prove.

No comments: