Sponsored Link •
What automated refactorings would you like to see?
Automated refactoring has come a long way. I remember, years ago, when I first saw John Brant and Don Robert’s Smalltalk Refactoring Browser at OOPSLA. I had a sinking feeling in my chest. It was great, it was powerful, and I couldn’t imagine Java tool vendors ever creating anything similar. After all, there wasn’t any demand – people didn’t even know what refactoring was. I thought that automated refactoring was going to be just another niche idea that started and ended in academia.
Well, I was wrong and I’m glad that I was wrong. Vendors took the leap. JetBrains (under the name Intellij) started to create a refactoring plug-in and then they decided to create Idea, a full IDE. Eclipse came along as well, adding refactoring support from the beginning. Now, automated refactoring tools are commonplace in the Java world but I think we can go further.
Here’s a little hit list of things I’d like to see in a refactoring tool; things I do all the time. I’m not sure that all of them can be automated easily, but I’d love to see an attempt.
Yes, Eclipse and Idea give us Extract Superclass, but why don’t they give us Extract Class? It seems like it would be relatively simple. An IDE could use roughly the same dialog that it uses for Extract Superclass, but instead of creating a superclass the IDE could create a new class, declare an instance of it in the old class, and then move all of the fields and methods that you’ve selected.
This is a minor one, but it’s handy. There are times when I want to create a delegating method for a static method. Unfortunately, Eclipse always makes the delegator static. It would be nice if there was a checkbox for this. I often make instance delegators when I’m trying to create a seam around a static method call.
I’d like to be able to select a set of parameters to a method and have my IDE create a new class for them, fixing up the code as it does it so that all of the references to the parameters are now references to the class. Again, this is handy when moving away from overly long parameter lists. I don’t think this has to be limited to parameters either. You should be able to select any group of fields or local variables and ask the IDE to create a class for them.
Many API developers still don’t realize that when they make classes and methods final they often make it impossible to mock them without special support. Eclipse makes it easy to create delegate classes, but it’s still a little harder than it needs to be. It would be nice to have a feature which takes a set of classes or a package and generates an interface and wrapper for each class. I can’t imagine using it all the time, but it sure would come in handy when I'm working with some of the more paranoid frameworks and libraries.
This is the big one. I’d like to be able to select a statement and move it up above the statement above it or below the statement below it, but only if the IDE can be certain that behavior will be preserved. In general, this problem is intractable – you can’t always tell whether a move would preserve behavior, but there are computable cases. No one would want to have their IDE freeze for as long as it takes to compute the worst of them, but if a tool allowed moves in the simple cases, I’d be happy.
That’s my short list for today. What would you like to see?
|Michael has been active in the XP community for the past five years, balancing his time between working with, training, and coaching various teams around the world. Prior to joining Object Mentor, Michael designed a proprietary programming language and wrote a compiler for it, he also designed a large multi-platform class library and a framework for instrumentation control. When he isn't engaged with a team, he spends most of this time investigating ways of altering design over time in codebases.|