Is C++ Just a Better C?
A lot of money and energy was spent in converting or writing new software in C++ during the 80s and 90s. Even nowadays, when the leading commercial language is Java, there is a lot of effort spent in learning and using C++ in several areas where performance is considered to be an important asset.
However, despite all these efforts after 20 years, C++ is not used to its full extent. Some features such as the STL have become really successful and widely accepted by the industry. On the other hand, other features such as checked exceptions and RTTI have been met with little enthusiasm.
It is necessary to understand what these features have in common and why they were not considered to be so useful as their creators supposed them to be. Especially when such features have been introduced more than a decade ago and are still nowhere near full acceptance.
One of the problems of the C++ language is that it has, more than once, introduced features that are difficult to use and/or implement. As a general rule, this is a disadvantage of languages designed by a committee. Some features end up becoming part of the standard document, but they have little support in the real world.
For example, a decade ago the designers of C++ though about the possibility of having templates defined in separate translation units from the ones where the templates are used. The intention is good, since templates take a long time to parse and compile.
However, the big problem with separate compilation of templates, provided by the external template keyword, is that it was never implemented by major compilers. The main justification is that it is a complicated feature to implement. Also, it would require modifications to the current way programmers declare and templates.
The result is that external templates are now viewed as a dead feature, something that might be useful but is not available in any of the major compilers.
A related problem for C++ is that nobody uses all its features. Due to the fact that there are competing implementation for the same concept (for example, two IO libraries — the old C-base library and a stream object-based library), C++ users have to decide which option to use. This may be done in a case-by-case basis, or even by the use of a coding style.
Big companies such as Google have decide to rule out most of the advanced features found in newer versions of C++. These features include exceptions, multiple inheritance, for example. What this means in practice is that C++ is being used just as a better C, without many of the features that its creators though would be useful.
On close inspection, it seams that C++ is mostly a language designed at two levels: the first level, incorporating the ideas of the day, which change every few years with the desires of researchers. Examples include checked exceptions and run time type information. In the process, lots of incompatible ways of writing the same code are introduced. For example, are you going to use return values or exceptions? Streams or standard buffered I/O? Both have its advantages and disadvantages, so you better know what they are.
In the other hand, there is also a second level dictated by developers, as they decide which subset of the language to use. Since it is not possible to use all the provided features at the same time, one has to selectively use C++ to create new software projects. One of the ways this is done is by adopting a styling convention. In this process, developers rule out a set of features that believe are not productive.
Still, another result of this evolutionary process is that there are some features that people don’t like, but that are not easy to substitute. For example, templates are a pain to create and even to use. However most developers use them because it is the only way to do some things in C++. Somebody else could create better container classes, but that would become a huge problem for compatibility with existing libraries.
C++ is an evolving language. As a consequence many of its features are not well developed. Other features have been rejected by the community as too complex or unsafe to use.
A large part of being a good C++ developer is understanding what are the good and bad parts of the language, and how to take advantage of them when necessary.
The Design and Evolution of C++, by Bjarne Stroustrup is a great book that explain the reasoning for most of the features in C++. It is a must read if you want to understand the initial phase of evolution of the language.
About the Author
Carlos Oliveira holds a PhD in Systems Engineering and Optimization from University of Florida. He works as a software engineer, with more than 10 years of experience in developing high performance, commercial and scientific applications in C++, Java, and Objective-C. His most Recent Book is Practical C++ Financial Programming.