The Yahoo XP group has been having a fairly heated debate about the term “refactoring”. When you refactor, do you change the behaviour of your code, or not? I decided to go have a look on dictionary.com, my ever-ready friend, for a definition.
It didn’t have a definition of “refactor”. It did, though, have “factor”, particularly as relates to the phrase “factor in”:
To figure in: We factored sick days and vacations in when we prepared the work schedule.
For me, that implies that the thing associated with the factoring in changes as a result of the new information.
Here’s where Dictionary.com says the word “factor” comes from:
factour, perpetrator, agent, from Old French
facteur, from Latin
factor, maker, from
facere, to make.]
We associate the root “fact” with “making things”, like factory. So sometimes I think of “refactor” as “remake”, which usually implies that there was a flaw in the original, or some new requirement, necessitating the remake. That means changing the behaviour.
I guess if you have a “refactoring phase” or you explicitly separate the idea of tidying up the code from remaking it, you might want to insist that refactoring shouldn’t change any of the code. I don’t think of refactoring as a process, and I haven’t found “refactoring phases” useful except as a smell that I’m not doing it enough as I’m going along. I just change things to put new behaviour in, so any “refactoring” I do is usually accompanied by a change in the code.
Refactoring techniques, though, are important tools that mustn’t change the behaviour of my code, because otherwise I won’t be able to control the explicit changes which I’m trying to make. I guess that’s where I see the confusion coming in. Refactoring isn’t a process. It’s just another tool, or a set of them, which lets me maintain my relationship with my code. My relationship with my code involves legibility, maintainability and predictability, and that particular behaviour should never change.
Update: An anonymous friend comments:
That makes sense; I wondered where the original use (ie: non-behaviour-changing transforms) came from. Aren’t words fun?