Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What C++ refactorings do you use in practice? [closed]

I'm going to create the comparison table of existing automated C++ refactoring tools as well as explore an ability of creation of such tool, free and open-source.

My question is: what refactorings do you really use in your everyday work? There are obvious things like renaming variable/class/method, but is there something specific for C++, like dealing with templates, STL, copy constructors, initializers, etc., etc?

I'm interested in building of realistic picture of all that little problems that C++ developer is facing each day in his coding and that could be automated at least in theory. I'm talking to my colleagues but that's probably not enough.

Thanks in advance.

like image 717
lithuak Avatar asked Nov 18 '10 11:11

lithuak


2 Answers

It is pretty clear from the answers that few C++ programmers have ever seen a real refactoring tool. Yes, they are quite rare and highly specific to the IDE you use. That's inevitable, there is otherwise no good way to find out what source code files contribute code to the final executable. The preprocessor makes it extra challenging, you need to know the macro values. A source code parser is required but not enough.

Visual Assist for VS is one I know of.

like image 62
Hans Passant Avatar answered Sep 30 '22 20:09

Hans Passant


As you said there are obvious things:

  • renaming is one
  • altering a function signature is another (especially since a function is almost necessarily duplicated: declaration in the header and implementation in the source)
  • renaming / moving a file (update of include directives)

Note that though it's basic, it's rarely well dealt with. My primary complaint being that comments are generally not updated (I am so not speaking about doxygen auto-generated useless clutter). So if I was describing the use of the class within a header, or the justification of using this class in another source file, the comment is now obsolete because by renaming the class no one will now know what it refers to...

There are however much more interesting cases:

  • When changing a function signature, you need to update all the call sites, the developer will need help for localizing them
  • With inheritance, the ability to act on all classes of a hierarchy: changing a function signature (once again) or adding/removing a virtual override.
  • With template: the Concept proposal having been dropped, it would be good if you could synthetise the requirements on the type passed (methods / inner types necessary) so that when altering those requirements (by modifying the template definition) one gets notified of the list of classes that are in use by this template and no longer conform to it (and shall be updated). Note that in case it's just renaming the type / method, you might want to automatically propagate the change, as long as it doesn't break anything else.

Good luck...

like image 39
Matthieu M. Avatar answered Sep 30 '22 20:09

Matthieu M.