Tuesday, October 20, 2009

The Hidden Costs of C++

Over at Rachels Lab Notes, Rachel Blum has a nice post about the hidden costs of C++ that pretty accurately captures one of my main complaints about the language. When I code in C I have a pretty accurate model in my head of what the generated code is going to look like and I can even evaluate the effectiveness of alternative expressions based on my understanding of what code (approximately) the compiler will generate. With C++, not so much. As Rachel points out, it's easy to imagine the code that

a = func( b, c );

will generate in C just by looking that the statement. With C++ we really have no idea. Is func a simple function? A class member function? A constructor? What about b and c? Will they invoke copy constructors? These and other questions can not be answered except by having detailed knowledge of the rest of the code, and even then it's not always clear to me what the resulting object code will look like. This makes it hard to generate efficient code with C++. For me, at least, dealing with that takes more effort than dealing with the code complexity of C that C++ claims to ameliorate.

No comments:

Post a Comment