Monday, March 26, 2007

Rediscovering Refactorings

Michael Feathers wrote a blog listing some of the refactorings he would like to see in IDEs. Two refactorings in particular caught my eye, Extract Class and Introduce Parameter Object. In fact, these refactorings have been available for quite some time via a third-party plugin for IntelliJ IDEA called Refactor-J, from Sixth & Red River Software.

Introduce Parameter Object is great for simplifying a long parameter list by condensing several parameters into a single parameter object. This can be a great way to clean up your design to make it easier to use, easier to read and comprehend, and easier to maintain. Parameter objects can stay as simple value objects, or they can evolve into something more intelligent, as needed.

Michael's request also includes that any arbitrary group of variables (fields or local variables) could also be converted into aggregate objects. If it is possible to implement, I'd like to see this as well. It could potentially be a very useful refactoring, allowing you to quickly sketch out the collaborating classes your design may need. Just start with basic ints and Strings and build your object-oriented design from that.

If you regularly do complex refactorings, or if you just happen to want more power out of refactoring, I suggest looking into the Refactor-J plugin. It has about 20 extra refactorings in total. Also, for more 'personalized' refactorings, you can always use the built-in Structural Search & Replace feature of IDEA. It takes a little getting used to, and it cannot do all kinds of refactoring, but it is often the best way to make refactoring-like changes to your code that cannot already be made with existing refactorings.

At the end of his post, Michael asks for what he calls 'intelligent statement move'. Well, unfortunately what he's asking for is not likely to be seen for a while, but with a sufficient suite of unit tests, the basic Move Statement Up/Down editor command (Ctrl-Shift-Up/Down) is sufficient for most purposes. It can even move syntactically correct blocks of code (you can select sytactic blocks with Ctrl-W), or even whole methods.

Have you ever dreamed up any special refactorings you would like to see in your IDE?


Post a Comment

<< Home