Why is Visual C++ lacking refactor functionality?

1,354

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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.

Solution 5

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.

Share:
1,354

Related videos on Youtube

val
Author by

val

Updated on July 05, 2022

Comments

  • val
    val almost 2 years

    Using train() and preProcess() I want to build a predictive model using PCA with the first 7 principal components as my predictors.

    The below works but I'm not able to specify the number of PCs:

    predModel2 <- train(diagnosis~., data=training2, method = "glm", preProcess = "pca")
    

    I've tried this to specify the number of PCs but I don't know how to incorporate it into train():

    training_pre<-preProcess(training[,ILcols],method = c("center", "scale", "pca"),pcaComp= 7)
    

    I've tried using:

    predModel2 <- train(diagnosis~., data=training2, method = "glm", preProcess = "pca", pcaComp=7)
    Error in train.default(x, y, weights = w, ...) : Stopping
    

    UPDATE: It seems I get around this by using predict() first:

    training2_pca<-predict(training_pre,training2_pca)
    train(diagnosis~., data=training2_pca, method = "glm")
    
    • Dylan Czenski
      Dylan Czenski over 8 years
      refactoring is difficult for C++ but I feel like VS should add a Rename all kind of functionality like the one in Xcode C++.
  • Doug T.
    Doug T. over 15 years
    Visual Assist X is pretty good and typically does the job pretty well. However, if you get all template meta-programy on it it can throw up its hands on some of your code.
  • Brian
    Brian over 15 years
    That's true. I've noticed it doesn't handle more than a few layers of templates very well (like when working with Boost).
  • davidsheldon
    davidsheldon over 12 years
    However it doesn't support VS2005 any more.
  • reder
    reder over 12 years
    No, pretty bad link indeed. The guy is frustrated, and not even polite (contacted the guy once, about some cleaarly abusive points, he did ot care). But yes, refactoring is clearly difficult (depending on code size), and one must think twice on initial design.
  • Zac
    Zac about 11 years
    So here we are stating Microsoft is poor in solving incredibly difficult tasks, while the Eclipse Foundation is better? I program in VS for project constraints, but when I need renaming a variale I launch Eclipse just for this...
  • Mark Simpson
    Mark Simpson over 10 years
    ReSharper is on the way, but it's not quite there yet :) resharper-support.jetbrains.com/entries/…
  • Joe
    Joe about 10 years
    Why is this an accepted answer? Parsing C++ code into a semantically meaningful form HAS to be done by a compiler. MS obviously owns the compiler that is included with their IDE. Why not use the same parsing code? It really doesn't matter how hard parsing is, because they already do it anyhow.
  • Tara
    Tara almost 10 years
    Btw: The point about horribly breaking your code is actually invalid if youre talking about Microsoft. They have lots of features that break your code.
  • schoetbi
    schoetbi over 9 years
    Refactoring is not imposible: See here whttp://www.youtube.com/watch?v=yuIOGfcOH0k. But I haven't found a publicly available version of it. See also here: phoronix.com/scan.php?page=news_item&px=MTEyMTE
  • polkovnikov.ph
    polkovnikov.ph over 9 years
    That's a bad link, because author lacks knowledge of C++. For example, he's unaware of RVO. Refactoring tools are quite straightforward if you're up to use Clang API, where authors have already gone through all that overload resolution hell. The problem is that MSVS lacks such an API.
  • GuardianX
    GuardianX about 9 years
    so when they are implemeting the symantic constructs of the language - it is easy enough for them, but alternating them in order to perform refactoring is hard. Makes a lot of sense..
  • Chance
    Chance almost 9 years
    Yes, it'll break the code but that's what the compiler is for. The 10% that the refactoring tool didn't catch will be quickly caught by the compiler; those are exactly the changes we don't have to fear. I'd rather do 10% than 100%.
  • aeroson
    aeroson over 8 years
    Microsoft Visual Studio 2015 is able to refactor rename some of the C++ code.
  • Clearer
    Clearer over 6 years
    There are already plenty of example of refactoring tools that work with C++, even when you posted this answer. The fact that VS is still missing this feature can not be for technical reasons, other than having a totally fubared compiler that VS can't work with. Both Clang and GCC allows any third party to implement this functionality. Even ctags allows limited refactoring -- a tool that's designed to work with an ancient version of C.
  • Kapil Vyas
    Kapil Vyas almost 6 years
    Question relates to VS 2008. This plugin works > VS 2013