Skip to main content

The Most Powerful Refactoring?

Posted by tball on March 7, 2005 at 2:01 PM PST

As earlier readers have probably figured, I'm working on automated Java refactoring technology these days. It's becoming a crowded field with some really good tools already out there, but since I'm a normal software engineer I know I can do better. As Alexander Pope stated, "Fools rush in where angels fear to tread," and as my family will attest, I am no angel.

Now that the Jackpot engine is humming along nicely, our marketing folks want it to demonstrate some "powerful" refactorings from Martin Fowler's book, Refactoring: Improving the Design of Existing Code. From a tool perspective, there are certainly some hairy refactorings to consider implementing, such as "Extract Method" or "Replace Inheritance with Delegation", but I do not use those very often, and when I do it's always by hand.

Perhaps I am looking at this problem incorrectly. The above book defines refactoring as "... the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure." I want to add to that description: "... or increases its clarity." As a production developer, I rarely get to work solely on my own code; I inherit other engineers' work and pass it on afterwards to still others. A big source of bugs in this environment is source that is hard to understand, code that doesn't clearly describe its functionality and the intentions of its authors. Consequently, much of my refactoring cleanup involves changes that make the code more "obvious" to the next engineer in the chain. Most well-applied refactorings do just that.

So what is my candidate for most powerful refactoring? It's "Rename Class", which isn't even in the book! "Rename Method" is, however, and the author's description of its benefits also apply to classes and variables. I use the beta 4.1 version of NetBeans, and find I'm frequently renaming classes since its refactoring support makes it both easy and fool-proof (being a fool, I need the proofing!). I change class, method and variable names as my understanding of their purpose improves, and a nice side-benefit is that it makes picking them from a code-completion list faster since their names are more obvious.

So, what refactoring has your vote as "most powerful"?

Related Topics >>