Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Tools

An Interview with Bjarne Stroustrup


The Future of C++

JB: Your research group is looking into parallel and distributed systems. From this research, have any new ideas for the new C++0x standard come about?

BS: Not yet. The gap between a research result and a tool that can be part of an international standard is enormous. Together with Gabriel Dos Reis at TAMU, I have worked on the representation of C++ aiming at better program analysis and transformation (eventually to be applied to distributed system code). That will become important some day. A couple of my grad students analyzed the old problem of multi-methods (calling a function selected based on two or more dynamic types) and found a solution that can be integrated into C++ and performs better in time and space than any workaround. Together with Michael Gibbs from Lockheed-Martin, I developed a fast, constant-time, dynamic cast implementation. This work points to a future beyond C++0x.

JB: You have some thoughts on how programming can be improved, generally. What are they?

BS: There is immense scope for improvement. A better education is a start. I think that theory and practice have become dissociated in many cases, with predictably poor results. However, we should not fool ourselves into seeing education and/or training as a panacea. There are on the order of 10 million programmers "out there" and little agreement on how to improve education. In the early days of C++, I worried a lot about "not being able to teach teachers fast enough." I had reason to worry because much of the obvious poor use of C++ can be traced to fundamental misunderstandings among educators. I obviously failed to articulate my ideals and principles sufficiently. Given that the problems are not restricted to C++, I'm not alone in that. As far as I can see, every large programming community suffers, so the problem is one of scale.

"Better programming languages" is one popular answer, but with a new language you start by spending the better part of a decade to rebuild existing infrastructure and community, and the advance comes at the cost of existing languages: At least some of the energy and resources spent for the new language would have been spent on improving old ones.

There are so many other areas where significant improvements are possible: IDEs, libraries, design methods, domain specific languages, etc. However, to succeed, we must not lose sight of programming. We must remember that the aim is to produce working, correct, and well-performing code. That may sound trite, but I am continuously shocked over how little code is discussed and presented at some conferences that claim to be concerned with software development.

JB: An area of interest for you is multi-paradigm (or multiple-style) programming. Could you explain what this is for you, what you have been doing with multi-paradigm programming lately and do you have any examples of the usefulness of multi-paradigm programming?

BS: Almost all that I do in C++ is "multi-paradigm." I really have to find a better name for that, but consider: I invariably use containers (preferably standard library (STL) containers); they are parameterized on types and supported by algorithms. That's generic programming. On the other hand, I can't remember when I last wrote a significant program without some class hierarchies. That's object-oriented programming. Put pointers to base classes in containers and you have a mixture of GP and OOP that is simpler, less error prone, more flexible, and more efficient than what could be done exclusively in GP or exclusively in OOP. I also tend to use a lot of little free-standing types, such as Color and Point. That's basic data abstraction and such types are of course used in class hierarchies and in containers.

JB: You are looking at making C++ better for systems programming in C++0x as I understand it, is that correct? If so, what general facilities or features are you thinking about for making C++ a great systems language?

BS: Correct. The most direct answer involves features that directly support systems programming, such as thread local storage and atomic types. However, the more significant part is improvements to the abstraction mechanism that will allow cleaner code for higher-level operations and better organization of code without time or space overheads compared to low-level code. A simple example of that is generalized constant expressions that allows compile-time evaluate of functions and guaranteed compile-time initialization of memory. An obvious use of that is to put objects in ROM. C++0x also offers a fair number of "small features" that without adding to run-time costs make the language better for writing demanding code, such as static assertions, rvalue references (for more efficient argument passing) and improved enumerations.

Finally, C++0x will provide better support for generic programming and since generic programming using templates has become key to high performance libraries, this will help systems programming also. For example, here we find concepts (a type system for types and combinations of types) to improve static checking of template code.

JB: You feel strongly about better education for software developers. Would you say, generally, that education in computer programming is appalling? Or so-so? If you were to design a course for high school students and a course (an entire degree) for university students intending to become professional, what would you include in these courses and what would you emphasize?

BS: Actually, I just took part in an effort to do that for the four undergraduate years. Unfortunately, the descriptions you find of our program on the web is still a mix of new and old stuff—real-world programs can only be put in place in stages. The idea is to give the students a broad view of computer science during the first two years ("making them ready for their first internship or project") and then using the next two years to go into depth in some selected areas. During the first two years, the students get a fairly classical CS program with a slightly higher component of software development projects than is common. They have courses in hardware and software (using C++), there is some discrete math, algorithms and data structures, (operating and network) systems, programming languages, and a "programming studio" exposing them to group projects and some project management.

JB: In an ideal world for you, what will C++0x be in terms of all the goodies in the new Standard Library and language?

BS: Unfortunately, we don't live in an ideal world and C++0x won't get all the "goodies" I'd like and probably a fewer "minor" features than I would have liked. Fortunately, the committee has decided to try for more and smaller increments. For example, C++0x (whether that'll be C++09 or C++10) will have only the preparations for programmer-controlled garbage collection and lightweight concurrency, whereas we hope for the full-blown facilities in C++12 (or C++13).

I do—based on existing work and votes—expect to get:

  • Libraries
    • Threads
    • Regular expressions
    • Hash tables
    • Smart pointers
    • Many improvements for containers
    • Quite a bit support for new libraries
  • Language
    • A memory model supporting modern machine architectures
    • Thread local storage
    • Atomic types
    • Rvalue references
    • Static assertions
    • Template aliases
    • Variadic templates
    • Strongly typed enums
    • constexpr: Generalized constant expressions
    • Control of alignment
    • Delegating constructors
    • Inheriting constructors
    • auto: Deducing variable types from initializers
    • Control of defaults
    • nullptr: A name for the null pointer
    • initializer lists and uniform initialization syntax and semantics
    • concepts (a type system for template arguments)
    • a range-based for loop
    • raw string literals
    • UTF8 literals
    • Lambda functions

For a more detailed description of both my ideals, the work of the ISO C++ standards committee, and C++0x, see my HOPL-iii paper: "Evolving a language in and for the real world: C++ 1991-2006. ACM HOPL-III" from earlier this year. Also, see the ISO C++ committee's web site where you can find more details than you could possibly want (search for "WG21" and look for "papers").

BS: C++ is often used in embedded systems, including those where safety and security are top priorities. What are your favorite examples and why do you think C++ is an ideal language for embedded systems especially where safety is a concern, aside from easy low-level machine access?

BS: Yes, and I find many of those applications quite exciting. Too often people think of computing as "what runs on a PC with a single user in front of it." Obviously, my Bell Labs background biases me towards noticing the uses of software in cell phones, telecommunications devices, and systems in general. So much of our infrastructure is invisible and taken for granted! "The gadgets" we can see. That's one reason I like embedded systems programming. Another is the stringent demands on correctness (even with some hardware malfunction) and performance. In such software, there is a need for clear design and precise expression of ideas that can challenge a language.

Among my favorite examples are the modern wind-power generators and the huge diesel engines that power the largest container ships. We can't talk about invisibility here, but then people don't see those huge "structures" as containing computers running software that is critical to their correct, efficient, and economical performance. I have also seen some interesting uses of C++ in aerospace, notably the new "Joint Strike Fighter" (the F-35), but my favorite is the higher levels of the Mars Rover software (scene analysis and autonomous driving). The whole Rover project is really a stunning success. Both Rovers have outlived their promised design life by a factor of 6 and are (as I write this) still working their way across Mars looking, prodding, and sending home data. Again, the Rovers themselves are just the visible part of a huge complex system: just try to imagine what it takes to get the data back to earth and analyzed. Almost all of computer science and almost all of our engineering skills are involved here somewhere. The range of skilled people involved is really hard to imagine. Too often we forget the people.

I don't think there exists an "ideal language" for these kinds of systems, but C++ is a good one. Part of the reason is that any large system, such as a cell phone or a Rover depends on its huge hidden infrastructure. Obviously, you don't have to use a single language for everything, but there are enough overlaping parts of applications for C++'s flexibility, generality, and concern for performance to come into play. Many languages deemed simpler achieve their simplicity through limiting their range of applications or by making great demands on the underlying hardware and (software) execution environments.

JB: Would you say that the document JSF++: Joint Strike Fighter Air Vehicle Coding Standards that can be found under your C++ links, under the point "For a look at how ISO C++ can be used for serious embedded systems programming" is generally a good guide for any embedded systems programming, and perhaps for other things as well?

BS: Yes, that's a good guide for the kind of applications for which it was written. For those, I'm convinced that it's the best of its kind; I helped write it. It is very important to note, though, that with experience, we will find improvements and if applied to areas for which it was not intended, it could do harm. For example, the JSF++ prohibits the use of free store (dynamic store) and exceptions, whereas for general programming you typically need to use those features to get the best code. However, for high-reliability, hard-real time code, the simple fact that a new and a throw can't (in general) be guaranteed to execute on a short, fixed, constant time makes them a no-no. I also recommend the ISO C++ committee's Technical Report on performance, which can also be found on my C++ page. It is primarily aimed at embedded systems programming, but discusses issues rather than lay out rules. Please also note that the JSF++ document is about half rationale: people should not be asked to do things "just because we say so." At least we can try to explain the reasons behind the rules.

In general, I think it essential that a coding standard is tuned to a specific application, organization, or application area. Trying to "legislate morality" for all users is counter-productive.

JB: What do you enjoy doing in your spare time? Have you read any books or watched any films lately that you liked, and if yes, why?

Spare time? I like to run and to sightsee when I have a chance (usually when traveling for something work-related). Taking photographs is an excellent excuse for spending a bit of extra time in interesting places. Spending time with family is a high priority, and a pleasure, of course. I read non-technical books essentially every day. That's mostly light reading to relax. I recently re-read some of Raymond Chandler's novels; they age well. I also just finished Terry Jones and Alan Ereira's "Barbarians" about how the Romans really were the destructive villains of the ancient world; that's a refreshingly different perspective. I have always been fascinated by history. There are so many parts of history that nobody would have believed it if it wasn't real—after all fiction has to be probable. And then, of course, you can't read just one book about history; you need to read a lot to understand the context of events and to avoid being sold a biased fairy tale version of something. Before that, I read Richard Dawkin's "Climbing Mount Improbable"; I basically have to re-learn biology because just about everything is new since I left school. Curiously, I'm often asked about my non-technical reading habits, so I posted a short list among my home pages.


James Buchanan is a programmer and freelance technical journalist. He can be contacted at [email protected].


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.