C++ 14 has been finalized

Posted Friday, Nov 21, 2014 by David Chapman

C++ is 35 years old, and the most recent standard, C++ 14 (based on the year, not the number of revisions) has just come out. Bjarne Stroustrup, the developer of C++, talked about goals for the next release, C++ 17, in an InfoWorld interview.

I’ve been using C++ for 23 years, since I got a copy of Datalight C++, which became Zortech C++ and finally Symantec C++ before being killed off. Over that period I’ve written about 800,000 lines of C++ code.

Originally the language was “C with classes;” it has grown in several different directions since then: multiple inheritance, exceptions, namespaces, templates, and lambda functions.  The most recent version (2013) of The C++ Programming Language by Bjarne Stroustrup is 1,368 pages long and presumably doesn’t include anything just added in C++ 14. For comparison, my 1978 copy of K&R C is 226 pages long.

Templates are one of the most-used features of the C++ language, intended to allow code to be written just once and adapted automatically by the compiler. Manual code copying is a long-standing source of bugs, and reducing it would be a good thing. However, with the development of the Standard Template Library (STL) and the Boost libraries, template programming morphed into metaprogramming – the use of code to generate code.

Templates were not originally designed to support metaprogramming, and the resulting code is almost “write only” – difficult if not impossible for the average programmer to understand or debug. Worse yet, the need for partial specialization has resulted in a lot of code copying. Multiple levels of derived classes mean that tracing through the code is tedious. And woe to the programmer who types the wrong incantation – the error messages for a single syntax error can be pages long.

I write high-performance software for the semiconductor Electronic Design Automation (EDA) industry. We “solve the unsolvable,” optimizing NP-Complete problems. Runtime is crucial to obtaining good results, so we have to understand our code completely, at all levels. This is difficult to impossible to do for STL or Boost code. For example, it took me about 15 minutes to trace through all the levels of code that implement std::vector so that I could determine its array resizing strategy. Multiply that by all of the other performance-related aspects of std::vector and writing my own just might take less time, in addition to having the performance and capabilities I need.

The other issue is that C++ tries to maintain compatibility with the C language.  This means retaining all of C’s warts, plus adding a few more. There are two incompatible memory allocators (operator new and malloc) and two incompatible text I/O subsystems (streams and fprintf). Operators like << and >> have been repurposed rather than define new syntax.

Now I hear about even more features being grafted on top of C++. This is beginning to sound like another “all things to all people” language that collapsed under its own weight – Ada. I think I’ll stick to using “C with Classes,” and if I ever get bored I’ll take a step back and see how all of this might be done better. I’ve written a few compilers along the way, and another can’t hurt.


No Comments