If you’ve seen the PDC prerelease of Visual Studio (codename Whidbey), you may have noticed the new “Refactoring” menu when editing C# code.
There are 3 criteria we use to select refactorings to implement Whdibey:
In my experience with Refactoring, there are two Refactorings that stand out as being more important in a tool than others:
BTW, I don’t expect users to think of RenameMethod, RenameClass, RenameField, etc. as being different things. There’s just Rename. Some of the knobs to turn are a bit different, and the internal workings may be different, but it’s not really important from a user’s perspective.
Note that except for the last bullet, none of this helps you do Object Oriented programming any better. I want to talk about that more; maybe in another blog entry.
Rename is pretty transparent – you know what it is, and what it does. But as I mentioned, it’s nice that can create a new class right away without having to worry about picking the right name. I know I can always fix it later. Sometimes that name becomes obvious after the class is coded & I can see its members.
Sometimes (this is neat) I’ll rename to what I think is the correct name, but when I see it in context I realize it is wrong. Then, with the actual usage in mind, I can rename again to something better.
If your spelling isn’t very good, you can code up what you want now & fix it later. No need to stop & consult a spell checker. (Or, if you’re me, you can fix other people’s spelling)
Extract Method is a wonderful luxury. It does a bunch of analysis to figure out what to pass, so I don’t have to. I just select some code & go.
In the Refactoring book, Fowler lists comments as a smell – if you have a comment, it indicates that some code is not as clear as it could be, and could benefit from Refactoring. I’ve seen people try to understand code by commenting it as they read & comprehend.
When I’m trying to understand a complex bit of code, I use ExtractMethod. I select a statement or block that is contributing to the complexity and give it a name by extracting it. After a few iterations, a complex function quickly becomes a simple one that reads like English. It’s nice.