PDA

View Full Version : Rename refactoring



Ola Eldoy
27-Mar-2012, 04:22 AM
I'm starting a new thread, to follow up on Stephen's suggestion


Hi Ola,

I'm fairly sure that better refactoring support is on the big list of possible improvements, but it never hurts to log specific suggestions. Is there a particular tool that you think does renaming well? If so (or even if not), you may want to float a scenario here in the forums (I'd start a new thread), get feedback and then log the result.

According to Martin Fowler (http://martinfowler.com/refactoring/), "Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior." So the goal is to improve the structure of a program, but maintain the behavior.

There are several refactorings (http://martinfowler.com/refactoring/catalog/index.html) listed, but I would like to start with one: Rename.

Glancing to Visual Studio's C# Rename Refactoring (http://msdn.microsoft.com/en-us/library/6kxxabwd.aspx), we find that there are in fact many rename operations. Resharper (http://www.jetbrains.com/resharper/features/code_refactoring.html) seems to be a great refactoring tool, also. Translating to VDF, I can think of the following:

Rename property
Rename local variable
Rename global variable
Rename local method
Rename global variable
Rename file
Rename class
Rename object
Rename struct
Rename constant
Did I forget anything?

So, just as we can right-click on a word in VDF Studio and select "go to definition", it should be possible to select "rename".

The rename operation should then rename all relevant occurrences of the selected term. This is the tricky part, where we manually have to search/replace in files. Normally, we need to manually check every occurrence to determine if it needs to be renamed or not. A simple search/replace routine does not "know enough" to decide this. But an intelligent rename refactoring feature would know more, thus reducing the need for manual labor. The ideal situation is when the Studio can do the renaming fully automated, but I believe this will not be feasible (or even possible?) in all cases. In this case, a list of suggested renames should be presented, allowing for manual verification.

I would suggest "start small", that is, pick the "low hanging fruit" where a feature is easy to implement, yet gives great benefits. "Rename local variable", "Rename global variable", "Rename global method", "Rename constant", and "Rename file" should be easy to fix. "Rename class" shouldn't be too hard, either (just remember to account for U_ and RefClass).

Your thoughts are welcome!

Larry R Pint
27-Mar-2012, 08:43 AM
An obvious and pertinent example is changing table and column names, now that 17.0 allows for longer names.