An Interview with Bjarne Stroustrup

C++ creator Bjarne Stroustrup discusses the evolving C++0x standard, the education of programmers, and the future of programming.


March 27, 2008
URL:http://www.drdobbs.com/open-source/an-interview-with-bjarne-stroustrup/207000124


JB: When did you first become interested in computing, what was your first computer and what was the first program you wrote?

BS: I learned programming in my second year of university. I was signed up to do "mathematics with computers science" from the start, but I don't really remember why. I suspect that I (erroneously) thought that computing was some sort of applied math.

My fist computer was the departmental GIER computer. It was almost exclusively programmed in Algol-60. My first semi-real program plotted lines (on paper!) between points on the edge of a superellipse to create pleasant graphical designs. That was in 1970.

JB: When you created C++, was the object oriented programming (OOP) paradigm (or programming style) obviously going to gain a lot of popularity in the future, or was it a research project to find out if OOP would catch on?

BS: Neither! My firm impression (at the time) was that all sensible people "knew" that OOP didn't work in the real world: It was too slow (by more than an order of magnitude), far too difficult for programmers to use, didn't apply to real-world problems, and couldn't interact with all the rest of the code needed in a system. Actually, I'm probably being too optimistic here: "sensible people" had never heard of OOP and didn't want to hear about it.

I designed and implemented C++ because I had some problems for which it was the right solution: I needed C-style access to hardware and Simula-style program organization. It turned out that many of my colleagues had similar needs. Actually, then it was not even obvious that C would succeed. At the time, C was gaining a following, but many people still considered serious systems programming in anything but assembler adventurous and there were several languages that—like C—provided a way of writing portable systems programs. One of those others might have become dominant instead of C.

JB: Before C++, did you "just have to create C++" because of the inadequacy of other languages, for example? In essence, why did you create C++?

BS: Yes, I created C++ in response to a real need: The languages at the time didn't support abstraction for hard systems programming tasks in the way I needed it. I was trying to separate the functions of the Unix kernel so that they could run on different processors of a multi-processor or a cluster.

JB: Personally, do you think OOP is the best programming paradigm for large scale software systems, as opposed to literate programming, functional programming, procedural programming, etc.? Why?

BS: No programming paradigm is best for everything. What you have is a problem and a solution to it; then, you try to map that solution into code for execution. You do that with resource constraints and concerns for maintainability. Sometimes, that mapping is best done with OOP, sometimes with generic programming, sometimes with functional programming, etc.

OOP is appropriate where you can organize some key concepts into a hierarchy and manipulate the resulting classes through common base classes. Please note that I equate OO with the traditional use of encapsulation, inheritance, and (run time) polymorphism. You can choose alternative definitions, but this one is well-founded in history.

I don't think that literate programming is a paradigm like the others you mention. It is more of a development method like test-driven development.

C++0x

JB: In your paper, "The Design of C++0x" published in the May 2005 issue of the C/C++ User's Journal, you note that "C++'s emphasis on general features (notably classes) has been its main strength." In that paper you also mention the most change and new features will be in the Standard Library. A lot of people would like to see regular expressions, threads and the like, for example. Could you give us an idea of new classes or facilities that we can expect to see in C++0x's Standard Library?

BS: The progress on standard libraries has not been what I hoped for. We will get regular expressions, hash tables, threads, many improvements to the existing containers and algorithms, and a few more minor facilities. We will not get the networking library, the date and time library, or the file system library. These will wait until a second library TR. I had hoped for much more, but the committee has so few resources and absolutely no funding for library development.

JB: Have you or others working on C++0x had a lot of genuinely good ideas for new classes or facilities? If so, will all of them be used or will some have to be left out because of time and other constraints on developing a new standard? If that is the case, what would most likely be left out?

BS: There is no shortage of good ideas in the committee or of good libraries in the wider C++ community. There are, however, severe limits to what a group of volunteers working without funding can do. What I expect to miss most will be thread pools and the file system library. However, please note that the work will proceed beyond '09 and that many libraries are already available; for example see what boost.org has to offer.

JB: When would you expect the C++0x Standard to be published?

BS:The standard will be finished in late 2008, but it takes forever to go through all the hoops of the ISO process. So, we must face the reality that "C++0x" may become C++10.

JB: Concurrent programming is obviously going to become important in the future, because of multi-core processors and kernels that get better at distributing processes among them. Do you expect C++0x will address this, and if so, how?

BS: The new memory model and a task library was voted into C++0x in Kona. That provides a firm basis for share-memory multiprocessing as is essential for multicores. Unfortunately, it does not address higher-level models for concurrency such as thread pools and futures, shared memory parallel programming, or distributed memory parallel processing. Thread pools and futures are scheduled for something that's likely to be C++13. Shared memory can be had using Intel's Threading Building Blocks and distributed memory parallel processing is addresses by STAPL from Texas A&M University and other research systems. The important thing here is that given the well-defined and portable platform provided by the C++0x memory model and threads, many higher-level models can be provided.

Distributed programming isn't addressed, but there is a networking library scheduled for a technical report. That library is already in serious commercial use and its public domain implementation is available from boost.org.

Educating the Next Generation

JB: Do you think programmers should be "armed and dangerous" with their tools like compilers, editors, debuggers, linkers, version control systems and so on very early on in their learning or careers? Do you think that universities should teach debugging and how to program in a certain environment (e.g. Unix) as well, for example?

BS: I'm not 100% sure I understand the question, but I think "yes." I don't think that it should be possible to graduate with a computer science, computer engineering, etc. degree without having used the basic tools you mention above for a couple of major projects. However, it is possible. In some famous universities, I have observed that Computer Science is the only degree you can get without writing a program.

I'm not arguing for mere training. The use of tools must not be a substitute for a good understanding of the principles of programming. Someone who knows all the power-tools well, but not the fundamental principles of software development would indeed be "armed and dangerous." Let me point to algorithms, data structures, and machine architecture as essentials. I'd also like to see a good understanding of operating systems and networking.

Some educators will point out that all of that—together with ever-popular and useful topics such as graphics and security—doesn't fit into a four-year program for most students. Something will have to give! I agree, but I think what should give is the idea that four years is enough to produce a well-rounded software developer: Let's aim to make a five-or-six-year masters the first degree considered sufficient.

JB: What should C++ programmers or any programmer do, in your view, before sitting down to write a substantial software program?

BS: Think. Discuss with colleagues and potential users. Get a good first-order understanding of the problem domain. If possible, try to be a user of an existing system in that field. Then, without too much further agonizing, try to build a simplified system to try out the fundamental ideas of a design. That "simplified system" might become a throwaway experiment or it may become the nucleus of a complete system. I'm a great fan of the idea of "growing" a system from simpler, less complete, but working and tested systems. To try out all the tool chains before making too grand plans.

How would the programmer, designer, team get those "fundamental ideas of a design"? Experience, knowledge of similar systems, of tools, and of libraries is a major part of the answer. The idea of a single developer carefully planning to write a system from the bare programming language has realistically been a myth for decades. David Wheeler wrote the first paper about how to design libraries in 1951—56 years ago!

JB: What type of programs do you personally enjoy writing? What programs have you written recently?

BS: These days I don't get enough time to write code, but I think writing libraries is the most fun. I wrote a small library supporting N-dimensional arrays with the usual mathematical operations. I have also been playing with regular expressions using the (draft) C++0x library (the boost.org version).

I also write a lot of little programs to test aspects of the language, but that's more work than fun, and also small programs to explore application domains that I haven't tried or haven't tried lately. It is a rare week that I don't write some code.

JB: In your experience, have there been any features of C++ that newcomers to the language have had the most difficulty with? Would you have any advice for newcomers to C++ or have you found a way of teaching difficult features of C++ saving students a lot of trial and error?

BS: Some trial and error is inevitable, and may even be good for the newcomer, but yes I have some experience introducing C++ to individuals and organizations—some of it successful. I don't think it's the features that are hard to learn, it is the understanding of the programming paradigms that cause trouble. I'm continuously amazed at how novices (of all backgrounds and experiences) come to C++ with fully formed and firm ideas of how the language should be used. For example, some come convinced that any techniques not easily used in C is inherently wrongheaded, hard to use, and very inefficient. It's amazing what people are willing to firmly assert without measurements and often based on briefly looking at C++ a decade ago using a compiler that was hardly out of beta—or simply based on other people's assertions without checking if they have a basis in reality. Conversely, there is now a generation who is firmly convinced that a program is only well-designed if just about everything is part of a class hierarchy and just about every decision is delayed to run-time. Obviously programs written by these "true OO" programmers become the best arguments for the "stick to C" programmers. Eventually, a "true OO" programmer will find that C++ has many features that don't serve their needs and that they indeed fail to gain that fabled efficiency.

To use C++ well, you have to use a mix of techniques; to learn C++ without undue pain and unnecessary effort, you must see how the language features serve the programming styles (the programming paradigms). Try to see concepts of an application as classes. It's not really hard when you don't worry too much about class hierarchies, templates, etc. until you have to.

Learn to use the language features to solve simple programs at first. That might sound trivial, but I receive many questions from people who have "studied C++" for a couple of weeks and are seriously confused by examples of multiple inheritance using names like B1, B2, D, D2, f, and mf. They are—usually without knowing it—trying to become language lawyers rather than programmers. I don't need multiple inheritance all that often, and certainly not the tricky parts. It is far more important to get a feel for writing a good constructor to establish an invariant and understand when to define a destructor and copy operations. My point is that the latter is almost instantly useful and not difficult (I can teach it to someone who has never programmed after a month). The finer details of inheritance and templates, on the other hand, are almost impenetrable until you have a real-world program that needs it. In The Art of Computer Programming Don Knuth apologizes for not giving good examples of co-routines, because their advantages are not obvious in small programs. Many C++ features are like that in that: They don't make sense until you face a problem of the kind and scale that needs that feature.

JB: Do you have any suggestions for people who are not programmers and want to learn how to program, and want to learn C++ as their first language? For instance, there's a book called Accelerated C++: Practical Programming by Example by Andrew Koenig and Barbara E. Moo. This book's approach is to teach by using the STL and advanced features at an early stage, like using strings, vectors and so on, with the aim of writing "real" programs faster. Would you agree that it's best to begin "the C++ way" if you could call it that, instead of starting off with a strictly procedural style and leaving classes, the Standard Library and other features often preceded with "an introduction to OOP" much later in a book?

BS: I have had to consider this question "for real" and have had the opportunity to observe the effects of my theories. I designed and repeatedly taught a freshman programming course at Texas A&M University. I use standard library features, such as string, vector, and sort, from the first week. I don't emphasize STL; I just use the facilities to have better types with which to introduce the usual control structures and programming techniques. I emphasize correctness and error handling from day 1. I show how to build a couple of simple types in lecture 6 (week three). I show much of the mechanisms for defining classes in lectures 8 and 9 together with the ways of using them. By lecture 10 and 11, I have the students using iostreams on files. By then, they are tired, but can read a file of structured temperature data and extract information from it. They can do it 6 weeks after seeing their first line of code. I emphasize the use of classes as a way of structuring code to make it easier to get right.

After that comes graphics, including some use of class hierarchies, and then comes the STL. Yes, you can do that with complete beginners in a semester. We have by now done that for more than 1,000 students. The reason for putting the STL after graphics is purely pedagogical: after iostreams the students are thoroughly tired of "calculations and CS stuff," but doing graphics is a treat! The fact that they need the basics of OOP to do that graphics is a minor detail. They can now graph the data read and fill class objects from a GUI interface.

JB: I read an interview in Texas A&M Engineering Magazine where you said, "I decided to design a first programming course after seeing how many computer science students—including students from top schools—lacked fundamental skills needed to design and implement quality software..." What were these fundamental skills students lacked, and what did you put in your programming course to address this issue?

BS: I saw so many students who simply didn't have the notion that code itself is a topic of interest and that well-structured code is a major time saver. The notion of organizing code to be sure that it is correct and maybe even for someone else to use and modify is alien: They see code as simply something needed to hand in the answers to an exercise. I am of course not talking about all students or just students from one university or from one country.

In my course I heavily emphasize structure, correctness, and define the purpose of the course as "becoming able to produce code good enough for the use of others." I use data structures and algorithms, but the topic of the course is "programming" not fiddling with pointers to implement a doubly linked list.

And yes, I do teach pointers, arrays, and casts, but not until well after strings, vectors, and class design. You need to give the students a feel of the machine as well as the mechanisms to make the (correct) use of the machine simple. This also reflects comments I have repeatedly had from industry: that they have a shortage of developers who understand "the machine" and "systems."

JB: You have said that a programmer must be able to think clearly, understand questions and express solutions. This is in agreement with G. Polya's thesis that you must have a clear and complete understanding of a question before you can ever hope to solve it. Would you recommend supplementary general reading like G. Polya's book, How to Solve It along with reading books on programming and technique? If so, what books would you recommend?

BS: I avoid teaching "how to think." I suspect that's best taught through lots of good examples. So I give lots of good examples (to set a standard) including examples of gradual development of a program from early imperfect versions. I'm not saying anything against Polya's ideas, but I don't have the room for it in my approach. The problem with designing a course (or a curriculum) is more what to leave out than what to add.

JB: What are the most useful mathematical skills, generally, that a programmer should have an understanding of if they intend to become professional, in your view? Or would there be different mathematical skills a programmer should know for different programmers and different tasks? If this is the case could you give examples?

BS: I don't know. I think of math as a splendid way to learn to think straight. Exactly what math to learn and exactly where what kinds of math can be applied is secondary to me.

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:

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].

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.