Sunday, January 09, 2005

A good refactoring

How do you know a refactoring is good? Are you moving code around or creating the perfect design, or are you actually making the current code base easier to use?

For myself, I can tell the difference between a good refactoring I'm doing and a navel gazing one early on.

In small refactorings:

1) Very quickly the refactoring cleans up a small amount of code.
2) You feel you can read the code quite easily
3) Generally it involves only four to five methods
4) It takes about ten minutes

In large-scale refactorings

1) You're usually refactoring to an existing pattern, either in your code or one thats known
2) Within a couple of hours the code is feeling better as it cleans up.
3) You have experimented with the code for at least a few weeks previously, and have arrived at the preferred pattern.
4) As you refactor the code cleans itself up, as the pattern has wide spread effects on your code.
5) The refactoring has unexpected benefits, things you didn't think of are better now.
6) It large refactoring is really a series of small refactorings that you apply over and over. YOU NEED TO FIGURE OUT WHAT THAT SEQUENCE IS, AND IT WILL TAKE LESS TIME.
6) It can take anywhere from a day to a couple of weeks.

0 Comments:

Post a Comment

<< Home