Refactoring is a fancy way of saying “optimizing your codebase”, but it’s a little more than that. Refactoring is a controlled technique for improving the design of an existing code base. It’s the process of taking an object design (in source code) and rearranging it in various ways to make the design more flexible and/or reusable. There are several reasons you might want to do this, efficiency and maintainability being probably the most important.

There are a series of “refactorings” that have generally been accepted as “common”. Martin Fowler is one of the father of these practices and contributed to create a catalog of them here.

Generally from a Software Configuration Management (SCM) perspective, it poses a challenge because when do perform a refactoring you end up touching potentially every file in the system but you can’t be certain which ones upfront. For example, let’s say I’m going to rename a method in a class (from getinvcdtlmt which doesn’t make much sense to getInvoicableCreditLimit). To do this, I could do a global search and replace (if my IDE had that capability) or manually change all the references to it. This means I hit every mention of this method in all my source. What if my source code was referring to this in multiple ways like through a pointer or something? A global search and replace might not work.

Bring on the tools. There are several tools on the market (mostly in the Java space) that perform these refactorings for you with a simple click of a button. In the example above, a global search and replace might be effective enough but for other refactorings (like splitting out a class into multiple classes) you need a tool that understands how code works, not text (or you end up doing this manually).

.NET proves to be an even more discreet platform for refactoring. There are a few tools out there but they’re either very early in development, difficult to use, don’t integrate very well with the Visual Studio .NET IDE, or just plain don’t work. Here are a few of the .NET tools I’ve found out there:


C# Refactory

C# Refactoring Tool

As time goes on I’m sure something will come out of this. The next version of Visual Studio .NET (Whidbey) will offer up the common patterns of refactoring, but that’s a year or so off. Lord knows I would love to come up with a definitive tool to do this, but given my current workload of projects (which I’m still trying to catch up with) I can’t rise to the task.

Anyways, if you’re interested in learning more about refactoring here are some links: