Why is Visual C++ lacking refactor functionality?

Viewed 42605

When programming in C++ in Visual Studio 2008, why is there no functionality like that seen in the refactor menu when using C#?

I use Rename constantly and you really miss it when it's not there. I'm sure you can get plugins that offer this, but why isn't it integrated in to the IDE when using C++? Is this due to some gotcha in the way that C++ must be parsed?

11 Answers

The syntax and semantics of C++ make it incredibly difficult to correctly implement refactoring functionality. It's possible to implement something relatively simple to cover 90% of the cases, but in the remaining 10% of cases that simple solution will horribly break your code by changing things you never wanted to change.

Read http://yosefk.com/c++fqa/defective.html#defect-8 for a brief discussion of the difficulties that any refactoring code in C++ has to deal with.

Microsoft has evidently decided to punt on this particular feature for C++, leaving it up to third-party developers to do what they can.

I'm not sure why it is like this, but third-party tools exist that help. For example, right now I'm evaluating Visual Assist X (by Whole Tomato). We're also using Visual Studio 2005.

Don't feel hard-done-by, it isn't available in VB.Net either :)

C++ is a HARD language to parse compared with C# (VB too unless you've "Option Explicit" and "Option Strict" switched on, it's difficult to tell exactly what any line of code is doing out of a MUCH larger context).

At a guess it could have something to do with the "difficulty" of providing it.

P.S. I marked my answer as community wiki because I know it's not providing any useful information.

I'd like to point out that Qt Creator (a C++ IDE which is compatible with VC++ libraries and build system) provides symbol renaming that works very well:

You can rename symbols in all files in a project. When you rename a class, you can also change filenames that match the class name.

Qt Creator - Refactoring: Renaming Symbols

Qt Creator's rename functionality gives you a list of the symbol references it found and an opportunity to exclude any of them before performing the replace. So if it gets a symbol reference wrong, you can exclude it.

Qt Creator Refactor Replace

So C++ symbol renaming is possible. Coming to VS from Qt Creator I feel your pain, to the point where I've considered converting preexisting VS projects of considerable size to use Qt Creator instead.

I don't buy the argument that this is specifically hard in C++. In addition to the fact that it already works very well in Qt Creator, there's the fact that the compiler and linker can find and match symbols: If that wasn't possible you couldn't build your application.

In fact, languages like Python that are dynamically typed also have renaming tools. If you can create such a tool for a language where there are no explicit references to variable type you can definitely do it for C++.

Case in point:

... Rope, a python refactoring library... I tried it for a few renames, and that definitely worked as expected.

Stack Overflow - What refactoring tools do you use for Python?

Related