Why is Visual C++ lacking refactor functionality?

后端 未结 11 1304
慢半拍i
慢半拍i 2020-12-12 20:15

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 constan

相关标签:
11条回答
  • 2020-12-12 20:47

    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.

    0 讨论(0)
  • 2020-12-12 20:54

    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.

    0 讨论(0)
  • 2020-12-12 20:56

    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.

    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?

    0 讨论(0)
  • 2020-12-12 20:58

    Install plugin which enables you that functionality: https://visualstudiogallery.msdn.microsoft.com/164904b2-3b47-417f-9b6b-fdd35757d194

    0 讨论(0)
  • 2020-12-12 21:03

    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.

    0 讨论(0)
提交回复
热议问题