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条回答
ゆ 、 Hurt°
2楼-- · 2019-01-21 06:48

devexpress provides Add-in Refactor! for C++ for VS2005 and VS2008.

查看更多
对你真心纯属浪费
3楼-- · 2019-01-21 06:50

Eclipse does few c++ refactorings including 'rename'. Check out this question here on StackOverflow.

It is also possible to use Microsoft compiler with Eclipse. Check out here.

Try Eclipse and see if it fits for you.

查看更多
Summer. ? 凉城
4楼-- · 2019-01-21 06:51
smile是对你的礼貌
5楼-- · 2019-01-21 06:53

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?

查看更多
forever°为你锁心
6楼-- · 2019-01-21 06:53

Well in spite of comments by all you experts I totally disagree that refactoring support issue has something to do with C++ language semantics or any language semantics for that matter. Except the compiler builder themselves don't choose to implement one in first case due to their own reasons or constraints whatsoever they maybe.

And offense not to be taken but I am sorry to say Mr jsb the above link you provided to support your case (i.e of yosefk) about C++ defect is totally out of question. Its more like you providing direction to "Los angeles" when someone asked for of "San Franisco".

In my opinion raising refactoring difficulty issue for certain language is more like raising a finger on language integrity itself. Especially for languages which is sometimes just pain.... when it comes to their variable declaration and use. :) Okay! tell me how come you loose track of some node within a node tree ... eh? So what it is do with any language be it as simple as machine level code. You know you VS compiler can easily detect if some variable or routine is dead code. Got my point?

About developing third party tool. I think compiler vendors can implement it far more easily and effectively if they ever wanted to then a third party tool which will have to duplicate all the parsing database to handle it. Nowadays compiler can optimize code very efficiently at machine code level and I am hearing here that its difficult to tell how some variable is used previously. You haven't paid any real attention to inner working of compiler I suppose. What database it keep within.

And sure its the almost same database that IDE use for all such similar purposes. In previous time compiler were just a separate entity and IDE just a Text Editor with some specialization but as times goes by the gap between compiler and IDE Editor become less and its directly started working on similar parsed database. Which makes it possible to handle all those intellisense and refactoring or other syntax related issues more effectively. With all precompile things and JIT compiling this gap is almost negligent. So it almost make sense to use same database for both purpose or else your memory demand go higher due to duplication.

You all are programmers - I am not! And you guys seems to be having difficulty visualizing how refactoring can be implemented for C++ or any language that I can't comprehend. Its just all about for something you have to put more effort for some less depending on how heavy is a person you trying push.

Anyway way VS a nice IDE especially when it comes to C#.

查看更多
叛逆
7楼-- · 2019-01-21 06:58

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.

查看更多
登录 后发表回答