Home > Articles > Programming > C/C++

An Interview with C++ Creator Bjarne Stroustrup

Danny Kalev interviews C++ creator Bjarne Stroustrup about the C++09 standard, why C++ was never meant to be just for OOP, and his affinity to Tolkien's hobbits.
Like this article? We recommend
  1. Congratulations on your forthcoming book Programming: Principles and Practice using C++! This is the first time you’re writing an introductory book. What has motivated you to write a book for beginners?

    → I had long found the C++ books for beginners unsatisfactory, but I couldn't do anything about that because I didn't have sufficient experience with teaching beginners. Then, more than three years ago (after I had moved to Texas A&M University to become a professor), I was a bit too loud in expressing my opinion of the programming skills of students and what I saw as the lack of focus on programming in their curriculum. Someone asked if I thought I could do better and I had to deliver. I designed a course, delivered it again and again together with an experienced lecturer who saved me again and again from my inexperience and overambition. The current course and the book that goes with it is the result. We have now taught well over 1,000 students, so we know that the approach works.

    My basic idea for the course was to list the knowledge and skills needed to start a project to produce code for the use of others than the programmers themselves. That list became the initial definition of the course. The point about "code for the use of others" is key. This leads to an emphasis on professionalism. When writing code that others rely on you need a responsible attitude to the structure of the code, the correctness ("how do you know it works?"), testing, and maintenance. It also implies that we can't let the student get stuck on obscure language-technical details (such as "exactly how does an unsigned short gets converted to an int?") beloved by teachers who like to set tricky tests. We have to get to the point where the students use object-oriented programming and generic programming because that's required for real-world applications. I also had to add something on graphics and GUI, but that's fun and helps in the appreciation of object-oriented techniques. Similarly, the STL features prominently to allow handling of data and to demonstrate generic programming techniques.

  2. In what ways was this writing experience different from writing a book for experienced programmers?

    →There was far more direct feedback. Often, I was writing and making slides well into the night to have something for the students in the morning. Seeing a blank wall of faces is a great incentive to do better. Conversely, to see those faces light up is a very direct reward. Another difference is that I have had to think harder about what I wanted to communicate. I also had to articulate how to get the ideas across. The latter becomes essential when I don't teach all the classes myself. For a teaching approach to scale beyond what an individual can do, its aims, principles, techniques, etc. must be articulated.

    I had to think hard about what I wanted to teach and how. Most people thought – and insist to keep thinking – that I was/am doing a C++ course. Actually, it is a course in programming. I use C++ to teach the principles and practical skills of programming. The teaching of programming language features is secondary. Obviously, C++ reflects my view of what programming should be so there is no major tension here, but I hope – and have reason to believe – that the skills can be applied with other languages.

    When writing for beginners, you also have to provide more support than for professionals. So there are more exercises, more repetition, more emphasis, more summaries, more diagrams, and more color than people are used to from my other books. The style is ever so slightly lighter than in my other writing. However, it is still a demanding book. I did not set out to write the simplest book on programming because that would not teach people enough to be useful. My aim is eventual professionalism – the ability to write code others can rely on. Obviously, not all of my students will become programmers (I started out with electrical and computer engineers), but I do not want to give the impression that programming is a shallow art for dilettantes.

    For many, my new book will actually be a second book on programming, but the first that aims at professionalism. I suspect that many will use the book for learning on their own, without the support of teachers and fellow students. That's hard, but I try to support that with detailed examples and condensed reference material. There is also material beyond what can be covered in a semester: text processing using regular expressions, numerical computation using an N-dimensional Matrix library, the basics of embedded systems programming, testing, and an overview of C programming from a C++ perspective.

  3. Has your experience as a professor at Texas A&M University brought new insights on how programming languages should be designed (for example, how to make programming languages easier to teach and learn, which features students find too confusing etc.)? If so, have these insights inspired you to design new C++ features?

    → Not really. I had done enough teaching at all levels – from middle school students to executives – even before I came to Texas that I had a pretty good idea what language ideas would help students. Unfortunately, the standards process is quite resistant to dramatic changes for the benefit of novices (of all backgrounds). The best thing that can be done for students is to provide more and better libraries. After that, anything that makes the language (and libraries) more consistent and less surprising helps.

    In particular, I'd give a lot for a very simple graphics and GUI library, a simple library for accessing a few web resources, and (for my engineering students) a good linear algebra library. In my class, I supply the graphics and the matrices myself, but it would be so much better to use someone else's – especially to use standard versions.

    However, we must be careful not to give the impression that calling other people's libraries is all there is to programming. One of the observations that influenced the design of my course and led me to present it as a book was repeated loud complaints from industry about the lack of capable systems programmers. Too many students graduate without exposure to the problems, tools, and constraints on solutions they will face in industry.

  4. The C++09 standard, which is due to be finalized within months, is the biggest standardization endeavor since 1998. In your opinion, what are the most important changes and additions that it includes? How will C++09 affect everyday the design, implementation and testing of new C++ projects?

    → If all goes well, we'll vote out a standard in October. After that comes a public review period and time for dealing with the comments. After that comes a lot of standards bureaucracy procedures. Even if we deliver the text on time, it's touch and go whether the 'x' in C++0x will be '9'. I fear we'll have to go hexadecimal.

    That said, I think that the new standard (C++0x) will be a boon to the C++ community in many ways. We'll have better tools for dealing with the (for most people) brave new world of concurrency. We'll have a few new libraries (regular expressions, hash tables, threads, etc.) and all the libraries will be easier to use and run faster thanks to new language features such as initializer lists, a more concise for loop, auto, etc.). Look at a few C++0x examples and consider what it would take to write them in C++98:

    // C++0x code:
    
    
    vector<string> v = { "Nygaard", "Kernighan", "Stepanov" };
    unordered_map<string,int> index;		// hash table
    for (auto p = v.begin(), p!=v.end; ++p) index[*p] = p-v.begin();
    
    enum class Traffic_light { red, yellow, green }; 
    enum class Alert_color { red, blue, green };
    int red = 2; 
    Alert_color c2 = red;		// error: no int to Alert_color conversion
    Alert_color c2 = Traffic_light::red;	// error
    Alert_color c2 = Alert_color::red;
    
    template<Container C>	// concepts
          requires<Comparable<C::value_type>>
                void sort(T&);
    sort(v);
    sort(red);	// error: int is not a Container
    vector<pair<string,int>> vp
           = { {"Nygaard",75}, { "Kernighan",66 }, {"Stepanov",57} };
    
    sort(vp);	// error: pair<string,int> is not Comparable (no operator<)

    Obviously, I'm restricting myself to tiny examples using the more obvious extensions. Note the absence of explanatory comments. Did you need any? It was hard for me that I could not use the C++0x in my new book. There are quite a few new features that help novices by simplifying notation and improving error handling.

  5. Some features are still missing in C++09: a networking library, object persistence, GUI, and database connectivity. In contrast, the new standard includes features such as rvalue references whose usefulness for the average C++ programmer is moot, in my humble opinion at least. Is the C++09 standard complete enough to suit the needs of the average C++ programmer in 2008?

    → No, there will not be nearly enough standard libraries for my taste. However, the C++0x will much more supportive than their C++98 counterparts. Simple C++0x library components, such as regular expressions, unordered maps (hash tables), and smart pointers are already being shipped by some vendors. The main contribution of the C++0x standard library will be to set concurrent programming on a firm basis with a machine model and a threads ABI . I would have liked support for higher level concurrency abstractions – directly using threads and locks is just about the worst way to try to exploit multi-cores. However, such higher-level support will come soon – standard or not – and the C++0x facilities provide a base. For example, the threading in Intel's TBB (Threading Building Blocks) is directly based on the (draft) C++0x threading ABI.

  6. Speaking of the average C++ programmer, what are C++’s major advantages over its newer rivals? In other words, what makes C++ relevant today – and tomorrow?

    → As ever: Performance, flexibility, generality, and access to hardware resources. When you encounter an application with "unusual requirements" you'll appreciate C++'s strengths compared to languages more finely tuned to a specific class of problems.

    Actually, the interest in C++ seems to be increasing again. For example, the C++ track at the SD conference in Santa Clara in early March was by far the largest track and significantly larger than last year (where is again was larger than the year before).

  7. A new standard is also a good opportunity to part gracefully with features that backfired or never soared. I can think of exception specifications and exported templates as examples, but there may well be others. Is it time to take a brave decision and remove such features or at least deprecate them?

    → Unfortunately, we can't do that. The committee cannot ban features that are used in innumerable programs and deprecation is widely ignored. Even the very few features we do manage to ban must be supported by implementers and the users complain bitterly about having to use compatibility switches. It is not easy to "be brave" with millions of lines of code and not responsible to "be brave" with hundreds of millions of lines of other people's code. So, I think that such "bravery" will have to wait for universal availability of near-perfect source-to-source translation tools. One of the advantages of a formally standardized language, such as C++, over proprietary languages is that the standard is a long-term commitment. Today's standard C++ will with absolutely minimal modifications run in 20 years, just as much 20-year old C++ does today.

  8. People (particularly those who do not use C++ as their primary language), still regard C++ as an object-oriented programming language. In practice however, state-of-the-art C++ switched to the generic programming paradigm years ago. Do the classic notions of OOP such as inheritance, virtual member functions, protected members and dynamic binding still matter?

    → It annoys me when I see recently written descriptions of C++ that would have been barely accurate in 1987. C++ was never meant to be just for OOP and certainly I never advertised it as such. See my publication list! Obviously, classical OOP still matters and will continue to do so. Kristen Nygaard (who invented OOP) used to comment that addition did not become useless or unused just because multiplication was invented and became fashionable. OOP serves a fundamental role that is not superseded by generic programming techniques. GP is currently fashionable and therefore over- and misused, but it is as fundamental as OOP and similarly has a permanent and prominent place in our programming and design tool chest. The interesting questions relate to exactly how to combine the two to get the best solutions for real-world problems (by "best" I mean things like correctness, maintainability, ability to reason about code, performance, and easy of reading and writing code). A classic example is the "draw all shapes" example that is usually seen as an example of object-oriented programming only:

    	void draw_all(vector<Shape*> vs)
    	{
    		for(int i = 0; i<v.size(); ++i) vs[i]->draw();
    	}

    But note that we are already using generic programming here. That vector is a parameterized type. In C++0x, we can write that a bit cleaner:

    	void draw_all(vector<Shape*> vs)
    	{
    		for (auto& x : vs) x->draw();
    	}

    However, we can also generalize draw_all() to apply to every data type that can be seen as a sequence:

        template<ForwardIterator Iter>
              requires SameType<Iter::value_type,Shape*>
        void draw_all(Iter b, Iter e)
    	{
              for_each(b,e, [] (Shape* p) { p->draw(); });
    	}

    Here, I again used C++0x features. In particular, I used concepts to get good type checking and the lambda notation for defining the operation to be applied to each element of a sequence. However, the point is that this is clearly generic programming that after a bit of conventional type manipulation invokes a virtual function on a class hierarchy. This is a prototype for a common and very general style of "mixed OOP and GP code" which (if you must) you can call multi-paradigm.

    We could call draw_all() like this:

    
    vector<Shape*> v = { new Circle({0,0},10), new Triangle(p1,p2,p3) };
    draw_all(v.begin(),v.end());
    
    set<Shape*> s = { new Elipses({0,0},10,20), new Square({10,10},p3) };
    draw_all(s.begin(),s.end());
  9. Something more personal. You were born into a working class family in Århus, Denmark, as you state in your bio. In the last 30 years or so, you’ve lived in the US. My acquaintance with these two countries, however superficial, suggests that there are significant differences between those two societies. What do you miss most from Denmark and the Danish heritage?

    →Denmark is a wonderful country that it is easy to be homesick for. It's a small country where most natural and cultural phenomena are on a human scale. It helps that it's also a rich, stable country running a full welfare state at a consistent profit. I miss my friends and family – but email and the web editions of Danish newspapers help me keep in touch. I miss the food – but I can get herring, salami, cheese, etc. airlifted in from a Danish shop in California. Danes are rather fond of food – I feel an affinity to Tolkien's hobbits. Danes tend to be significantly more trusting than Americans – I miss that. On the other hand, I could not have done my work in Denmark. Something on the scale of Bell Labs could not be built and sustained in Denmark.

  10. Finally, an inevitable question: Are you planning a C++09 edition of the The C++ Programming Language?

    →I'm thinking about that. I have to write a 4th edition, but it is non-trivial to decide what it should be. Each edition has had a separate aim and scope as the C++ community evolved. Including the standard libraries, the C++0x standard might come close to 2,000 pages. I don't think my 4th editions should compete with that in either style or size.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020