Useful Tools: Refactoring code the easy way

Everybody has their own favorite development IDE.  Some love Eclipse, others adore Xcode, and a few old school types swear by simple text editors and shell scripts. (Hi Pov!)

While cleaning up the Dink source I’ve been really getting my money’s worth out of Visual C++ with the Visual Assist add-on.

Safely renaming variables

One of the more useful features of Visual Assist is intelligently renaming a variable or function name across a project.

As an example, I could safely rename the horribly named global int variable “mode” to “g_gameMode” .  It’s smart enough to ignore locally defined “mode” variables or the word mode used in other contexts, such as functions or comments.

With its new name it will be safer use Search and Replace to make it GetGlobals->GetMode() later or something if I want to later.

Renaming library functions across multiple projects

Let’s say for some reason you wanted to rename RTFont::Load to RTFont::LoadTrueType but you don’t want to break things in old projects.

Here is a trick to safely rename things across multiple projects:

  • Create a new solution called AllProjects and add each existing project to it
  • Use Visual Assist’s rename or other refactoring tools to modify them all at once
  • Keep the solution around for anytime you need to globally modify things

When you have tools to make normally monotonous chores a breeze, you’re that much more likely to actually do it!

If your IDE can’t do stuff like that it might be time to find one that can.

Leave a Reply

Your email address will not be published. Required fields are marked *