Linked by David Adams on Sat 11th Oct 2008 16:48 UTC, submitted by IndigoJo
General Development Eric Raymond is working on an essay, putatively titled "Why C++ Is Not My Favorite Programming Language". In his announcement, he calls it "an overcomplexity generator", "bloated, obfuscated, unwieldy, rigid, and brittle", and alleges that these characteristics appear in C++ applications also. I contend that many of the complaints about C++ are petty or are aimed at specific libraries or poor documentation and that many of the features commonly regarded as unnecessary (and excluded from intended replacements) are, in fact, highly useful. C++: the Ugly Useful Programming Language
Permalink for comment 333596
To read all comments associated with this story, please click here.
setec_astronomy
Member since:
2007-11-17


Problem with this comparison is, to enable inheritance and polymorphism C++ translates every call into a virtual method table lookup....
Which is exactly the same a lookup map for methods!
Depending on the compiler you might get efficient code, but you cannot rely on it.


This is incorrect (or at least a little bit misleading, depends on what you mean by "inheritance and polymorphism", emphasis mine). The virtual function table is only created for functions, that are declared virtual. Other, non-virtual class member functions are resolved statically [1], e.g. at compile time, so (apart from the - nowadays compareably small - abstraction penalties) there should be no loss of performance when calling non-virtual class member functions compared to procedural functions. There are situations, where the lookup process and/or the table introduce unacceptable overheads (esp. in numerical sensitive / scientific code, cf. [2] for a very good introduction to this problem set + examples how to avoid it ).

While the virtual function lookup is indeed the "default" way to introduce polymorphism to C++ class hirachies, there are first-class-citizen alternatives
available for situations where other approaches are more appropiate (static polymorphism via template engines, static polymorphism via Barton-and-Nackman type template voodoo, carefully designed class hirachies with helper-classes, etc.)

[1] http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20...
[2] http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/techniques01...

Reply Parent Score: 1