Opportunistic Refactoring

You're getting all ready to implement some new functionality. You look over the class that you're going to be changing, and notice something that irritates you: a method that belongs somewhere else, or a temporary variable that doesn't need to be there at all, or whatever.

Got UnitTests?

Take a minute or two before you start adding the new functionality. Muck about with the code until you aren't irritated by it any more: move methods around, change their names, whatever you feel like doing. Do it in small bites, and run your UnitTests every time you change something. If you break something, go back to whatever you just did, figure out the problem, and fix it.

There, that wasn't too hard, was it? Didn't take long, either. And now you feel better about your code, so when you go on and add the new piece of code you'll be happier and more focused on it because you won't have the niggling irritation in the back of your mind.

ProgrammingIsFun.


CategoryRefactoring

EditText of this page (last edited April 2, 2003) or FindPage with title or text search