Massive Search And Replace

Strategy for initial refactoring of code where the variable names consists mainly of acronyms. Find every instance of the solitary letter p, and replace it with a more descriptive name. Even if that name is only SomeObject?, because you don't know what that variable does yet, it has the effect of significantly improving the readability of the code.

Before doing this, check to see whether the new variable name is already in use in the scope of the old variable name. You could end up squashing two variables into one, or hiding a variable from an outer scope. If the variable names are consistently bad however, this will rarely be a problem, as it's unlikely that your new threeWordVariable will collide with their tlv's :)


I would recommend against this strategy. There is too much risk and too little benefit.

May be true as is. Good news is that several current development IDEs have or will have refactoring tools that help do that safely and quickly.

If the code is poor, I suspect there is also a lack of unit tests to perform regression testing as you make changes. Also, globally changing a single variable name will not make a noticeable improvement in the code.

As an alternative, focus instead on a routine that you are going to be forced to change. Write a regression unit test for the routine. Clean up the routine and its internal variables. Improve the name of the method and propagate it outward. Clean up the names of called methods (one at a time) and clone them. Slowly purge the old name from the system.

The advantages to this approach are:


See: ReadWriteGrep


EditText of this page (last edited August 6, 2004) or FindPage with title or text search