views:

1669

answers:

7

I have just started using Visual Assist X for C++ refactoring in Visual Studio 2008. It is quite good, but IMO, not to the same level as what ReSharper has for C#. I am wondering what people are using for C++ refactoring, especially for larger code base.

Here are the add-ins that I have tried so far: * Visual Assist X * Refactor! Pro

Meanwhile, does anyone know if Visual Studio 2010 will have any real C++ refactoring tool built in?

Many Thanks!

Minyu

+1  A: 

Manual Labor.
Seriously, visual assist doesn't even come close to what these crazy C# guys do.

shoosh
A: 

See also good-refactoring-support-for-c

Martin Beckett
+2  A: 

I use Visual Assist X and find it to be a excellent tool. It may not be as good as Resharper, but it's still better than nothing.

Soo Wei Tan
I continued to use Visual Assist X for my C++ projects and found it adequate in most cases, and as you said, better than nothing :)
Minyu
A: 

I use my brain and my fingers.

Justicle
LOL! I wish I have enough of those :)
Minyu
+14  A: 

Not really an answer, more like musings on the subject (though it does answer your side question about VS2010).

The problem with C++ refactoring is that, unlike code completion which only needs to be "good enough", refactoring operations such as "rename method" should just work. If you have to manually do a Find on your code afterwards to verify that it didn't skip any methods, what's the point of the feature?

This means that C++ editor with refactoring support must have perfect understanding of C++ syntax and all compile-time semantics. This becomes important when templates get involved - a method call that has to be renamed might be made on a receiver which is a result of some nontrivial template function call (consider the case where it's std::bind!), or a combination of such. This means that supporting C++ refactoring is a task that is an order of magnitude more difficult - you have to lift all template instantiation logic from the compiler, including template specialization, SFINAE, etc. Keeping in mind that templates are Turing-complete, you effectively end up writing a full-fledged interpreter.

Getting back to real world. Current and past versions of Visual Studio used a simplified parser for all editor-related tasks, which is why IntelliSense worked sporadically, failing on many less trivial expressions, and why there is no refactoring (it just wouldn't work reliably).

In VS2010, this has been replaced with a new engine which is based on the front-end to EDG C++ compiler - as such, it can fully grok arbitrary complex C++ code. I've actually tested it on some very non-trivial things and blogged about the results, which are pretty amazing.

Unfortunately, the team (apparently) didn't have time to fully use the capabilities new parser, so currently they're only used for IntelliSense and Find References/Symbols. Thus, there's no out-of-the-box C++ refactoring in VS2010 beta.

The good part of it is that now the new parser is there, reliable refactoring is possible to implement, and I see very few excuses not to use the data to enable full-fledged C++ refactoring eventually. I do not know if there are any specific plans for this, and I haven't seen any public announcements, but I'd be surprised if this feature isn't at least considered for the next release. Your best bet to affect it is to open a Microsoft Connect feature request for C++ refactoring (surprisingly, I cannot find an existing one... surely there are many people who want this?) and vote for it.

Pavel Minaev
+1 For interesting musing
Andy J Buchanan
Appreciate your great insight! I will enter a feature request at Microsoft Connect. But at this late stage, I wonder if they will be able to release anything that is not already in VS2010 beta.
Minyu
There is an old MS Connect ticket (98701) about VS2005's feature inconsistency between C++ and C#, including the lack of refactoring. That was closed as won't-fix then.I just entered a new ticket for VS2010. Votes for it will be appreciated.
Minyu
Here is the ticket link:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=478772
Minyu
MS has also mentioned that they will be providing APIs to the Intellisense data base (but not for VS2010's release unfortuantely). This should let 3rd parties like Whole Tomato produce some pretty nice enhancements.
Michael Burr
A: 

I use regular expressions global search and replace in visual studio. Good enough for me :)

Igor Zevaka
Renaming is indeed a common refactoring activity. But it's just one of many others. Extract methods is another, which obviously cannot be assisted by simply regex.
Minyu
Pavel Minaev
When I want to limit the scope of the search and replace i just go thru all the open windows and rely on compiler to pick up the erraneous replacements. This would obviously not work well in a very large project. Having said that, I never found myself wishing there was a C++ refactoring tool.
Igor Zevaka
A: 

C++ maintenance programming on windows obviously not a significant enough economic endeavor to warrant a refactoring user interface around the EDG C++ compiler by 2010. Go Microsoft! They would save money on internal development if they had this. Well managed company for sure!

bewilderment