Home > Articles > Programming > C/C++

An Interview with Barbara Moo on C++11

  • Print
  • + Share This
  • 💬 Discuss
C++ Primer has been one of the most popular C++ textbooks for nearly two decades. Now in its new fifth edition, it covers all of the new C++11 core features and library changes. Danny Kalev interviewed co-author Barbara Moo about the new edition of C++ Primer, the writing process, her experiences from the early days of AT&T’s C++ project, and her future plans.

Danny Kalev: Congratulations on the fifth edition of C++ Primer! Currently, this is one of the first C++11 books in the market. What were the main challenges involved in writing about C++11? Do you feel that C++11 is easier to teach than former variants of the language, or is it the other way around?

Barbara Moo: Thanks! Being early definitely had its challenges. I started writing before the standard was finalized, and there were a couple of places where I had to revise what I’d written due to late-breaking changes in the final version of the standard. 

More importantly, until fairly late I didn’t have a compiler that could compile all the code examples. Unusually among C++ books, nearly all the code in the Primer is directly compiled. That is, I have a set of tools that lets me insert compiled code fragments into the final text of the book. Whenever I change an example or get a new compiler, I “recompile the book” so I always know that the examples compile and execute correctly. 

Of course, I couldn’t compile the examples for features that weren’t yet implemented.  In those cases, I had to fake the related code.  Not surprisingly, I found bugs when I first compiled those examples. Fortunately, the GCC 4.7 release came out before I shipped the book, and that release handles all but two of the features we cover in the Primer.  So, I was able to check all but a couple code examples and am really grateful for the timing of that release!

As to whether it’s easier to teach (and to learn!) original C++ or C++11, the answer depends on what teaching strategy is used.  In the Primer, we teach the language as an integrated whole.  We do so because we think it is definitely easier to learn C++11 that way.  I think that it would be much harder to teach (or learn) C++ by first mastering the original language and then learning the C++11 features. 

The reason I think it’s easier to teach the C++11 features right from the start is that there are a handful of features—auto, decltype, range-based for, and smart pointers—that simplify getting readers up to speed.  Using auto and decltype meant that we didn’t have to spend much time explaining ungainly type declarations such as vector<string>::const_iterator. Using smart pointers, and the library string and vector types, meant that we could talk about writing classes earlier in the book. Moreover, by using these library facilities, readers can write pretty sophisticated classes without having to worry about copy control.

Danny: Many C++ Primer readers are beginners making their first steps in C++. What are your recommendations and guidelines for learning C++ systematically? On which C++ features should newcomers focus?

Barbara: I guess I have one hard and fast recommendation:  Learn the library before learning lower-level concepts. Use smart pointers, string, and vector, not ordinary pointers and arrays! Too many books still teach readers bad habits, such as using fixed length arrays for string data. Understanding how to use vectors and strings is so much easier than learning how to deal with pointers and arrays. Low-level code involving arrays is harder to write, harder to understand, and nearly impossible to get right! 

Other than that, it’s hard to know how people will learn a new language. In particular, the Primer has always assumed the reader has already programmed in some language. The level of experience the beginner has affects how they should learn the language.

One enhancement we made in this edition is that we’ve included icons in the margins to help guide the reader. We’ve distinguished those sections that we think pretty much every C++ programmer needs to know from those that can be skipped or skimmed until a problem arises that requires that particular feature. Particularly in Part I, where we cover the basics of the language, readers should feel free to skip sections that are not marked as essential and plan to come back and learn the other material as needed.

The Primer is also frequently used by folks who want to brush up on the C++ they already know. With this edition we think even somewhat experienced C++ programmers will want to read the Primer to get up to speed on the new C++11 features.  For those readers, we’ve provided a separate table of contents that lists sections that describe the features added by the C++11 standard, and we have marginal icons that highlight the sections that cover the new features.

Danny: Let’s talk about the writing process. When you’re writing a book, how many hours every day do you dedicate to writing? Do you write everywhere or is there a specific location (e.g., your home porch, a study or a favorite café) dedicated to this task? What usually inspires you to embark on a new writing project?

Barbara: Ah, the life of a writer. Honestly, the answer to how many hours is somewhere between 0 and 12!  I have a nice office at home where I sit staring at my screen for hours on end.

Danny: Does the emergence of electronic books and book readers affect the way you write today in any way?

Barbara: Not yet.  Because this is a revision of an existing book, we necessarily stayed with the existing approach. 

We used LaTeX to do the typesetting, and sent the machine-readable text to AW for conversion for e-readers. I was delighted that one of the early Amazon reviews noted that the “fonts and spaces are perfect for a programming book.”  I do think LaTeX does a beautiful job of typesetting.  Another reviewer noted that the Kindle edition is “very good” so I infer that the AW folks did a fine job on the translation to the electronic version.

Danny: What is your advice for new authors who wish to write programming books? In your opinion, what are the ingredients of a good programming book?

Barbara: The best advice I can give is advice that was given to me: When you think you’re done, you’re no more than half-way there!  A book requires an enormous amount of revision.  More than you think…..and then well, a bit more.

Moreover, inevitably when one sets out to teach a programming language, there are many intertwined concepts. Carefully thinking through the order in which topics are covered is essential. Once you’ve got that order, you need to stick to it. Nothing is so frustrating as a lot of forward references (or worse, using a feature that hasn’t yet been covered without bothering to note that fact!). Some forward references are unavoidable, but strive to minimize them.

Danny: Back in the early 1980s, you managed a project that would become one of the biggest successes of the software industry--the C++ project. You worked with gurus such as Bjarne Stroustrup, Andrew Koenig, Stan Lippman and others. What was it like to work with so many brilliant minds? Can you share with the readers a remarkable anecdote from those days?

Barbara: What was it like: challenging, exhilarating, exhausting, fun! When folks think of AT&T they probably figure we had lots of resources, but we were always a pretty small group that was kind of outside the mainstream of the business. Dealing with that corporate reality presented many more challenges than working with all these great people. 

It was pretty much of a whirlwind in those early days, and I don’t know whether it counts as “remarkable,” but one dreadful moment was in June 1989. We had just shipped what was then a long-awaited major revision, Release 2.0 [of Cfront, the first commercial C++ implementation]. Unfortunately, after we’d shipped, we discovered some not too terrible bug, but one that would affect binary compatibility going forward. So, we had to fix it. 

But, we’d already shipped to manufacturing. The folks who would handle distribution already had a labeled release, and we were not at all confident that we could just ship them a new tape and that the old one would be properly disposed of. But, we also didn’t want to ship with an altogether updated release number such as 2.0.1. That’d just be too embarrassing. Someone, I’ve forgotten who, suggested that we could label the corrected version “2.00” (note the extra zero).  It was a good thing we did because if I recall correctly some customers did get the wrong version!  Anyway, as a result, we always thought of that release as “2 dot uh oh.”

Danny: You have a broad perspective of the evolution of C++. What are your predictions regarding future programming? Do you see any other programming language replacing C++ as the workhorse of core programming, for example?

Barbara: Oh, you know that’s really a hard question. Back in the mid 80s when I first started working with C++ someone asked a similar question about what programming language would folks be using in the year 2000.  The joke then was, no one knew but that it would be called Fortran!

Danny: The software industry, and C++ in particular, are by and large a men’s habitat. In your opinion, what makes female presence so rare in this industry? What attracts you to this field?

Barbara: I’m not sure C++ is more or less male dominated than other language/operating system type software.  And, honestly, it’s not a question I’ve ever thought about too deeply. At AT&T we had a number of women who worked in the compilers group and on C++ in particular. 

Personally, I kind of stumbled into working on C++. I started my career as a banker, but I didn’t like that work all that much. In the meantime, I’d met folks who worked in the computer industry and they just seemed so much more engaged with what they were doing. I was lucky to get a job at the computer center at Columbia and went back to school to study CS, and as I was finishing up my MS was again lucky to get a job at Bell Labs. My first job at Bell Labs was with the compilers department. From there I stumbled into the C++ group.

The thing that engages me about the field is that it is intellectually challenging but comprehensible, if that makes sense. At AT&T most of the work (such as switching systems and the business systems that large telephone companies use to manage their business) are so large and so complex that one person can’t hope to comprehend them.  That wasn’t the case for a project like C++. One could understand the issues, even if it required a bit of thought.

Danny: Looking back at a long and full-of-accomplishments career, what do you consider as your biggest achievement thus far? Is there something that makes you especially proud?

Barbara: Throughout my career I’ve been more on the management side than on the “doing” side of things. In pretty much every project I’ve worked on I’ve had folks tell me that I was the “best boss” they’d ever had. That’s the greatest compliment I can imagine. 

Danny: What are your plans for the future?

Barbara: Getting some sleep:-)

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus