Why is Visual C++ lacking refactor functionality?

2019-01-21 06:25发布

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条回答
不美不萌又怎样
2楼-- · 2019-01-21 06:59

I've been using Visual Assist X with visual studio for about one year and a half. It's an incredible tool that helps you a lot with ordinary C++ code, but it doesn't perform very well on templated code. For instance, you if have a sophisticated policy-based template design, it won't know how to rename your variables, and the project won't compile anymore.

查看更多
我命由我不由天
3楼-- · 2019-01-21 07:01

There is a lot of fud and confusion around this issue. This amazing youtube video should clear up why C++ refactoring is hard: https://www.youtube.com/watch?v=mVbDzTM21BQ

tl;dr Google refactors their entire 100 million line C++ codebase by using a compiler (Clang + LLVM) that allows access to its intermediate format.

Bottom line, third parties are screwed here, there is no realistic way for them to refactor VS C++ unless MS outputs intermediate results the same way. If you think of it from the programming problem perspective this is obvious: in order to refactor VS C++ you have to be able to compile C++ the exact same way VS does with the same bugs, limitations, flaws, hacks, shortcuts, workarounds, etc. The usual suspects like Coderush and Resharper do not have the budget for that kind of insanity although apparently they are trying but it has been years...

http://www.jetbrains.com/resharper-cpp/

Update 2016: Resharper now does a decent job at C++ refactor. Limitations are purely for large / gigantic projects.

查看更多
三岁会撩人
4楼-- · 2019-01-21 07:01

MS has finally done this: https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-33-C-Refactoring-in-Visual-Studio-2015#time=04m37s

They have started doing this about 10 years ago, I remember watching ms channel9 long ago.

查看更多
贪生不怕死
5楼-- · 2019-01-21 07:03

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.

查看更多
神经病院院长
6楼-- · 2019-01-21 07:05

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.

查看更多
登录 后发表回答