Review of Modern C++ Programming with Test-Driven Development

My review of a book written by Jeff Langr entitled Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better.

General Information

Book's cover

  • Author: Jeff Langr
  • Title: Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better
  • Publisher: Pragmatic Bookshelf
  • Release Date: October 2013
  • Pages: 366

More information can be found on the publisher’s website.

Review

Books about programming languages are very often focused solely on the language itself. They describe the syntax and semantics of the language and shows ways of utilizing its main features when writing code. Usually, they present the latest version of the language that was available at the time of writing. However, due to their narrow scope, they do not delve into other programming-related topics, such as design and testing. Instead, they just refer you to other sources. On the other hand, books about these other topics use only very basic language features to make their content accessible to a wide range of programmers. For example, they may still use C++98 even when newer standards exist (C++11 and also C++14). Then, it is up to the reader to put all the pieces together so he or she can develop well-designed, tested software in contemporary languages.

For a long time, I wished there was a book on C++ that would combine the use of modern language features and good design and testing principles. And since late 2013, there is: Modern C++ Programming with Test-Driven Development by Jeff Langr. The book focuses on test-driven development (TDD), which is my favorite technique to develop clean code that works. Apart from this, however, it also concentrates its attention on good design, use of C++11 features to write better code, and ways of unit-testing your applications in C++.

The book is very well written, clearly organized, and really keeps your attention. You will learn how to develop code that is easy to read, testable, maintainable, and extendable. The examples in the book utilize many good design principles, such as writing code at a single level of abstraction or single-responsibility principle. After reading the book, you will learn:

  • What is TDD and how to use it in modern C++ to write high-quality code.
  • How to write good and fast unit tests in C++ testing frameworks.
  • What are test doubles (stubs, mocks) and why they are useful.
  • How to work with legacy code that was written without tests.
  • Advanced topics, like designing and testing multi-threaded code.
  • Many useful design and testing concepts.

The only criticism I have is inconsistent use of uniform initialization (the author sometimes uses () and sometimes {} without any apparent system) and use of several testing frameworks throughout the book. However, from another viewpoint, the use of different testing frameworks can be seen as a positive because it makes you realize that it is the underlying principles that matter, not the syntax.

I can heartily recommend the book to all C++ developers, no matter what their experience with C++, TDD, design, or testing is. As Uncle Bob indicated in the foreword to the book, its title is not the best. His suggested title is Software Craftsmanship: With Examples in Modern C++. Indeed, the book shows you how to develop high-quality software in modern C++ in a sustainable manner.

If you would like to know more about TDD and have not read the classic book Test Driven Development: By Example by Kent Beck, I can also recommend it.

Leave a Comment.