Book Review: Programming: Principles and Practice Using C++, 2nd Edition

I learned C++ the hard way: in the early 1990’s, the best reference was Ellis’s and Stroustrup’s The Annotated C++ Reference Manual. At the advice of a good friend, I bought a copy, read it cover to cover several times, and spent the next several years of my career banging my head against the wall in largely C-only development projects trying to get mindshare to do things in C++. As a result, I learned a lot of bad habits at first, and wasn’t always the first guy to pick up on then-new things like the Standard Template Library when it became available. Add my extensive experience with Qt, and my C++ experience is actually quite spotty — there’s definitely room for improvement.

As a result, I jumped at the chance to review Bjarne Stroustrup’s Programming: Principles and Practice Using C++, 2nd Edition (Amazon link). This is an entry-level textbook on programming in C++ for new software developers; its target is obviously an undergraduate class for computer science majors, rather than a reference for a seasoned software developer. (If you’re looking for C++ for the seasoned developer, check out Stroustrup’s The C++ Programming Language, 4th Edition.)

Programming: Principles and Practice using C++ is an excellent modern introduction to what it means to be a programmer, while teaching all of the essentials of C++ you’re likely to need for your first few years. It covers a lot — C++ syntax, data types, the basics of object-oriented design, generic programming through templates, testing, and many other topics. The book is chock-full of code, often showing the iterative nature of programming as Stroustrup lays out the requirements for a program, and then shows version after version that works towards meeting those requirements. It clearly demonstrates how good software developers should approach programming problems, and is as much a book about thinking about programming as it is a book about programming. Which is, I think, exactly what the neophyte needs.

Don’t look here for a lot of information about clever data structures or algorithms — and that’s a good thing. Stroustrup leverages the STL for that, and emphasizes something I think good programmers already have learned — the best code is usually the code you didn’t write. There’s short discussions about some algorithms, of course, as befits a book on programming, as well as the idea behind an algorithm. But, for example, instead of learning to program a red-black tree, Stroustrup points the reader towards the STL’s map, and leaves it at that.

It’s scrupulously up to date, too, covering relevant portions of the latest C++14 standard, as well as using C++11 everywhere — which is great, because most compilers are C++11 compliant anyway, and students should be able to compose and understand programs using the latest language features.

Refreshingly, the book includes not just a discussion of object-oriented programming through the classic example of graphical programming, but actually enables readers to do simple graphical programming through a library on top of FLTK. In discussing the design and implementation of the library, Stroustrup covers classic object-oriented programming, including decomposition, inheritance, and data hiding. While the example is old, Stroustrup’s coverage of it is refreshingly up to date and thorough,

The strongest parts of the book are probably on the topic of generic programming and testing: one of the multi-chapter examples is a re-implmentation of the std::vector class, including almost everything in the standard library. This is an excellent introduction to a number of topics, including API design, memory management, pointers, templates, and generic programming in general. A little later is an excellent chapter going over iterators, looking at iterators as a classic example in generic programming.

It speaks highly of the book that I learned a few things in my read of the book; in some cases it was clarifying the reason behind a lesson I learned in the school of hard knocks, which is great to see in an introductory book of this sort. It was also refreshing to see how programming is taught today, especially using a language as fundamental as C++ is in the industry. In hiring engineers, I worry about the large number of developers who start with Java and never really get back to the basics; Stroustrup covers the basics quite nicely (including a chapter on embedded systems programming) without writing a textbook that’s only about the basics.

I’d recommend this book strongly to anyone just starting out in software development, and with some caveats for developers who already have significant programming experience. I think there’s someone for everyone in it, although the high price means if you’re skilled at teaching yourself programming languages — or just want to brush up on C++11 and C++14 — this might not be the most affordable purchase, even if it is a great read. But as an introductory textbook, it’s hard to beat, giving you a firm start in the fundamentals of programming in today’s world.

Leave a Reply