The A-Z of programming languages: C++

Bjarne Stroustrup of C++ fame dissects the history of his famed programming language

1 2 3 4 5 6 Page 2
Page 2 of 6

What are the main differences between the original C with Classes and C++?

Most of the differences were in the implementation technique. C with Classes was implemented by a preprocessor, whereas C++ requires a proper compiler (so I wrote one). It was easy to transcribe C with Classes programs into C++, but the languages were not 100% compatible. From a language point of view, the major improvement was the provision of virtual functions, which enabled classical object-oriented programming. Overloading (including operator overloading) was also added, supported by better support for inlining. It may be worth noting that the key C++ features for general resource management, constructors and destructors, were in the earliest version of C with Classes. On the other hand, templates (and exceptions) were introduced in a slightly later version of C++ (1989); before that, we primarily used macros to express generic programming ideas.

Would you have done anything differently in the development of C++ if you had the chance?

This common question is a bit unfair because of course I didn't have the benefits of almost 30 years of experience with C++ then, and much of what I know now is the result of experimentation with the earlier versions of C++. Also, I had essentially no resources then (just me -- part time) so if I grandly suggest (correctly) that virtual functions, templates (with "concepts" similar to what C++0x offers) and exceptions would have made C++85 a much better language, I would be suggesting not just something that I didn't know how to design in the early 1980s but also something that -- if I magically had discovered the perfect design -- couldn't have been implemented in a reasonable time.

I think that shipping a better standard library with C++ 1.0 in 1985 would have been barely feasible and would have been the most significant improvement for the time. By a "better library," I mean one with a library of foundation classes that included a slightly improved version of the (then available and shipping) task library for the support of concurrency and a set of container classes. Shipping those would have encouraged development of improved versions and established a culture of using standard foundation libraries rather than corporate ones.

Later, I would have developed templates (key to C++ style generic programming) before multiple inheritance (not as major a feature as some people seem to consider it) and emphasized exceptions more. However, "exceptions" again brings to a head the problem of hindsight. Some of the most important concepts underlying the modern use of templates on C++ did not exist until a bit later. For example, the use of "guarantees" in describing safe and systematic uses of templates was only developed during the standardization of C++, notably by Dave Abrahams.

How did you feel about C++ becoming standardized in 1998 and how were you involved with the standardization process?

I worked hard on that standard for years (1989-1997), as I am now working on its successor standard: C++0x. Keeping a mainstream language from fragmenting into feuding dialects is a hard and essential task. C++ has no owner or "sugar daddy" to supply development muscle, "free" libraries and marketing. The ISO standard committee was essential for the growth of the C++ community and that community owes an enormous amount to the many volunteers who worked (and work) on the committee.

What is the most interesting program that you've seen written with C++?

I can't pick one and I don't usually think of a program as interesting. I look more at complete systems -- of which parts are written in C++. Among such systems, NASA's Mars Rovers' autonomous driving subsystem, the Google search engine and Amadeus' airline reservation system spring to mind. Looking at code in isolation, I think Alexander Stepanov's STL (the containers, iterators and libraries part of the C++ standard library) is among the most interesting, useful and influential pieces of C++ code I have ever seen.

Have you ever seen the language used in a way that was not originally intended?

I designed C++ for generality. That is, the features were deliberately designed to do things I couldn't possibly imagine -- as opposed to enforce my views of what is good. In addition, the C++ abstraction facilities (e.g., classes and templates) were designed to be optimally fast when used on conventional hardware so that people could afford to build the basic abstractions they need for a given application area (such as complex numbers and resource handles) within the language.

So, yes, I see C++ used for many things that I had not predicted and used in many ways that I had not anticipated, but usually I'm not completely stunned. I expected to be surprised, I designed for it. For example, I was very surprised by the structure of the STL and the look of code using it; I thought I knew what good container uses looked like. However, I had designed templates to preserve and use type information at compile time and worked hard to ensure that a simple function such as less-than could be inlined and compiled down to a single machine instruction. That allowed the "weaving" of separately defined code into efficient executable code, which is key to the efficiency of the STL. The biggest surprise, I guess, was that the STL matched all but one of a long list of design criteria for a general-purpose container architecture that I had compiled over the years, but the way STL code looked was entirely unexpected.

1 2 3 4 5 6 Page 2
Page 2 of 6
Shop Tech Products at Amazon