views:

488

answers:

12

While C++ Standards Committee works hard to define its intricate but powerful features and maintain its backward compatibility with C, in my personal experience I've found many aspects of programming with C++ cumbersome due to lack of tools.

For example, I recently tried to refactor some C++ code, replacing many shared_ptr by T& to remove pointer usages where not needed within a large library. I had to perform almost the whole refactoring manually as none of the refactoring tools out there would help me do this safely.

Dealing with STL data structures using the debugger is like raking out the phone number of a stranger when she disagrees.

In your experience, what essential developer tools are lacking in C++?

+10  A: 

In your experience, what essential developer tools are lacking in C++?

Code completion. Seriously. Refactoring is a nice-to-have feature but I think code completion is much more fundamental and more important for API discoverabilty and usabilty.

Basically, tools that require any undestanding of C++ code suck.

Konrad Rudolph
I've found code completion to be fairly useless unless I know exactly what I'm looking for; an apropos command is much more usable for "discoverability"
Paul Nathan
Personally, I find that code completion just tends to get in my way. It is better to just read the documentation and know the library/API well before using it, instead of depending on the IDE to tell you what you want.
Evan Teran
I agree that completion could be better done. I se Code:Blocks and a lot of the time it works well, but it tends to barf on templates. The reason is easy to see - a completion engine must parse C++ code on the fly and doing that for templates is not what you would call trivial.
anon
If you want near-perfect code completion for C++, then have at look at VC++2010. I've tested it on an example which choked every other C++ code completion engine I know of (a polymorphic Boost.Lambda), and it managed to handle it perfectly. I've posted the sample code and the findings on my blog: http://blogs.msdn.com/pminaev/archive/2009/06/09/c-intellisense-in-vs2010.aspx
Pavel Minaev
I've been playing with KDevelop recently, and its code completion is pretty good. I've actually been pretty satisfied with it. Vim's OmniCompletion is also very, very good.
greyfade
Visual Assist X (http://www.wholetomato.com/) does a very good job completing C++ code in VS, I cant live without it.
Emile Vrijdags
It also does some refactoring like renaming, extract method, ... pretty well.
Emile Vrijdags
@greyfade: OmniComplete is completely broken on my machine. Care to take a stab at my related question? http://stackoverflow.com/questions/1115876I've yet to see a competent code completion tool that can handle templates (I use them *a lot*).
Konrad Rudolph
+22  A: 

My dream tool would be a compile-time template debugger. Something that'd let me interactively step through template instantiations and examine the types as they get instantiated, just like the regular debugger does at runtime.

jalf
A very interesting idea.
Pavel Minaev
You might be interested in this (very old and obviously dead, but IMO nevertheless interesting) article: http://accu.org/index.php/journals/390. `:^>
sbi
Thats a very interesting thought. I had never considered actually needing the type information itself, but now that you mention it a fantastic idea +1
Martin York
It seems obvious - template metaprogramming is a turing-complete language after all, so why shouldn't you be able to debug it the way you do with other languages? Static asserts are basically the TMP equivalent of debugging with printf, which is hardly satisfactory. And @Pavel, does that mean you'll get it into VC11? ;)
jalf
+4  A: 

A fast and reliable indexer. Most of the fancy features come after this.

fnieto
+3  A: 

I'm pretty happy with the state of C++ tools. The only thing I can think of is a default install of Boost in VS/gcc.

Paul Nathan
7GB+ of addition, those that don't use Boost will love you. ;D
KTC
7gb? boost src size is 50 mb
f0b0s
http://sourceforge.net/projects/boost/files/boost/1.39.0/ zipped size is 50mb, probable unzipped size is ~200mb or so? 200mb is a-ok on modern systems...
Paul Nathan
Those that don't use boost are insane.
GMan
Some Boost libraries have to be built, it's not all templates... and when you do that and build the libraries with debug info, you get about 1Gb of output (last I checked anyway, which was several years ago).
Pavel Minaev
If you build everything, with all variant (single/multi thread, shared/static library etc.) like a compiler will have to install because it can't predict which version you'll want to use, it's about 4GB for each target platform. Take VC, it will have to install both x86 and x64 versions, that take it up to 7GB+.
KTC
Hunh. 7GB is big, but I'd still accept it. (Although I think that the full set of combinations should only be generated when needed...).
Paul Nathan
A boost library shipping with your compiler could be "pre-compiled" to strip out all support for other compilers.
MSalters
On the other hand, I'm curious which C++ tools you live with.
Amit Kumar
@Amit: I use g++ or the CLI to Visual Studio; I also use a somewhat customized emacs. For debugging I use Visual Studio.
Paul Nathan
+2  A: 

A tool all on it's own: Naming Conventions.

David Anderson
It's not that we don't have naming conventions for C++, it's that we have more than one. I really don't understand why people aren't willing to stick to the ones used by the standard library, as we do in every other languages. Gladly, Boost at least does that, but why no-one else?
Pavel Minaev
Having different naming conventions lets you see at a glance which code is boost/stl-code and which code is something else... it's a feature :^)
Jeremy Friesner
@Pavel: They do this because there were other naming conventions in place when the C++ std lib was born. `:)`
sbi
+6  A: 

Code generation of class methods. When I type in the declaration you should be able to figure out the definition. And while I'm on the topic can we fix "goto declaration / goto definition" always going to the declaration?

Refactoring. Yes I know it's formally impossible because of the pre-processor - but the compiler could still do a better job of a search and replace on a variable name than I can maually. You could also syntax highlight local, members and paramaters while your at it.

Lint. So the variable I just defined shadows a higher one? C would have told me that in 1979, but c++ in 2009 apparently prefers me to find out on my own.

Some decent error messages. If I promise never to define a class with the same name inside the method of a class - do you promise to tell me about a missing "}". In fact can the compiler have some knowledge of history - so if I added an unbalanced "{" or "(" to a previously working file could we consider mentioning this in the message?

Can the STL error messages please (sorry to quote another comment) not look like you read "/dev/random", stuck "!/bin/perl" in front and then ran the tax code through the result?

How about some warnings for useful things? "Integer used as bool performance warning" is not useful, it doesn't make any performance difference, I don't have a choice - it's what the library does, and you have already told me 50 times. But if I miss a ";" from the end of a class declaration or a "}" from the end of a method definition you don't warn me - you go out of your way to find the least likely (but theoretically) correct way to parse the result.
It's like the built in spell checker in this browser which happily accepts me misspelling wether (because that spelling is an archaic term for a castrated male goat! How many times do I write about soprano herbivores?)

How about spell checking? 40 years ago mainframe Fortran compilers had spell checking so if misspelled "WRITE" you didn't come back the next day to a pile of cards and a snotty error message. You got a warning that "WRIET" had been changed to WRITE in line X. Now the compiler happily continues and spends 10mins building some massive browse file and debugger output before telling you that you misspelled prinft 10,000 lines ago.

ps. Yes a lot of these only apply to Visual C++.

pps. Yes they are coming with my medication now.

Martin Beckett
Try Comeau compiler and you will see what friendly error messages are...
fnieto
You're telling the compiler: treat the usual case specially. The same again and again.
Amit Kumar
+2  A: 

Refactoring, Refactoring, Refactoring. And compilation while typing. For refactorings I am missing at least half of what most modern Java IDEs can do. While Visual Assist X goes a long way, a lot of refactoring is missing. The task of writing C++ code is still pretty much that. Writing C++ code. The more the IDE supports high level refactoring the more it becomes construction, the more mallable the structure is the easier it will be to iterate over the structure and improve it. Pick up a demo version of Intellij and see what you are missing. These are just some that I remember from a couple of years ago.

  • Extract interface: taken a view classes with a common interface, move the common functions into an interface class (for C++ this would be an abstract base class) and derive the designated functions as abstract

  • Better extract method: mark a section of code and have the ide write a function that executes that code, constructing the correct parameters and return values

  • Know the type of each of the symbols that you are working with so that not only command completion can be correct for derived values e.g. symbol->... but also only offer functions that return the type that can be used in the current expression e.g. for

    UiButton button = window->...

At the ... only insert functions that actually return a UiButton.

Harald Scheirich
+3  A: 

A common tool to enforce coding standards.
Take all the common standards and allow you to turn them on/off as appropriate for your project.

Currently just a bunch of perl scrips usullay has to supstitute.

Martin York
+5  A: 

The main problem with C++ is that it is hard to parse. That's why there are so very few tools out there that work on source code. (And that's also why we're stuck with some of the most horrific error messages in the history of compilers.) The result is, that, with very few exceptions (I only know doxygen and Visual Assist), it's down to the actual compiler to support everything needed to assist us writing and massaging the code. With compilers traditionally being rather streamlined command line tools, that's a very weak foundation to build rich editor support on.

For about ten years now, I'm working with VS. meanwhile, its code completion is almost usable. (Yes, I'm working on dual core machines. I wouldn't have said this otherwise, wouldn't I?) If you use Visual Assist, code completion is actually quite good. Both VS itself and VA come with some basic refactoring nowadays. That, too, is almost usable for the few things it aims for (even though it's still notably less so than code completion). Of course, >15 years of refactoring with search & replace being the only tool in the box, my demands are probably much too deteriorated compared to other languages, so this might not mean much.

However, what I am really lacking is still: Fully standard conforming compilers and standard library implementations on all platforms my code is ported to. And I'm saying this >10 years after the release of the last standard and about a year before the release of the next one! (Which just adds this: C++1x being widely adopted by 2011.)

Once these are solved, there's a few things that keep being mentioned now and then, but which vendors, still fighting with compliance to a >10 year old standard (or, as is actually the case with some features, having even given up on it), never got around to actually tackle:

  • usable, sensible, comprehensible compiler messages (como is actually pretty good, but that's only if you compare it to other C++ compilers); a linker that doesn't just throw up its hands and says "something's wrong, I can't continue" (if you have taught C++ as a first language, you'll know what I mean); concepts ('nuff said)
  • an IO stream implementation that doesn't throw away all the compile-time advantages which overloading operator<<() gives us by resorting to calling the run-time-parsing printf() under the hood (Dietmar Kühl once set out to do this, unfortunately his implementation died without the techniques becoming widespread)
  • STL implementations on all platforms that give rich debugging support (Dinkumware is already pretty good in that)
  • standard library implementations on all platforms that use every trick in the book to give us stricter checking at compile-time and run-time and more performance (wnhatever happened to yasli?)
  • the ability to debug template meta programs (yes, jalf already mentioned this, but it cannot be said too often)
  • a compiler that renders tools like lint useless (no need to fear, lint vendors, that's just wishful thinking)

If all these and a lot of others that I have forgotten to mention (feel free to add) are solved, it would be nice to get refactoring support that almost plays in the same league as, say, Java or C#. But only then.

sbi
Um, I've looked at the implementation of both STLPort and gnu's libstdc++. Neither of their IOStreams call printf under the hood.
Evan Teran
you can do a: `egrep -R "sn?printf" /usr/include/stlport` if you like, there is only a few references to them in the whole library, none of which are used for iostreams.
Evan Teran
+6  A: 

If talking about MS Visual Studio C++, Visual Assist is a very handy tool for code completition, some refactorings - e.g. rename all/selected references, find/goto declaration, but I still miss the richness of Java IDEs like JBuilder or IntelliJ.

What I still miss, is a semantic diff tool - you know, one which does not compare the two files line-by-line, but statements/expressions. What I've found on the internet are only some abandoned tries - if you know one, please write in comment

CsTamas
+2  A: 

Intelligent Intellisense/Code Completion even for template-heavy code.

When you're inside a function template, of course the compiler can't say anything for sure about the template parameter (at least not without Concepts), but it should be able to make a lot of guesses and estimates. Depending on how the type is used in the function, it should be able to narrow the possible types down, in effect a kind of conservative ad-hoc Concepts. If one line in the function calls .Foo() on a template type, obviously a Foo member method must exist, and Intellisense should suggest it in the rest of the function as well.

It could even look at where the function is invoked from, and use that to determine at least one valid template parameter type, and simply offer Intellisense inside the function based on that.

If the function is called with a int as a template parameter, then obviously, use of int must be valid, and so the IDE could use that as a "sample type" inside the function and offer Intellisense suggestions based on that.

JavaScript just got Intellisense support in VS, which had to overcome a lot of similar problems, so it can be done. Of course, with C++'s level of complexity, it'd be a ridiculous amount of work. But it'd be a nice feature.

jalf
I think I read somewhere that, beginning in one of the next versions, VS will use the actual compiler for Intellisense.
sbi
+4  A: 

A compiler which tries to optimize the compilation model.

Rather than naively include headers as needed, parsing them again in every compilation unit, why not parse the headers once first, build complete syntax trees for them (which would have to include preprocessor directives, since we don't yet know which macros are defined), and then simply run through that syntax tree whenever the header is included, applying the known #defines to prune it.

It could even be be used as a replacement for precompiled headers, so every header could be precompiled individually, just by dumping this syntax tree to the disk. We wouldn't need one single monolithic and error-prone precompiled header, and would get finer granularity on rebuilds, rebuilding as little as possible even if a header is modified.

Like my other suggestions, this would be a lot of work to implement, but I can't see any fundamental problems rendering it impossible.

It seems like it could dramatically speed up compile-times, pretty much rendering it linear in the number of header files, rather than in the number of #includes.

jalf
Isn't that what PCHs _are_?
sbi
in a way - but with PCH's, it is only applied to *one* header, and you have to explicitly declared it as such, and jump through a lot of hoops to ensure it'll work correctly. Why not parse *every* included header individually like this?
jalf