Book Review: Effective C++ by Scott Meyers

A while ago, I read Effective C++ by Scott Meyers, and I would like to recommend it.

You can read tutorials, play with the language, maybe read The C++ Programming Language by Stroustrup himself, and be able to write fully functioning C++ programs that pass all the tests, and seem to work. But still, they can have more or less subtle problems, which might manifest as random crashes, resource leaks, scalability problems, or problems with reusability and maintenance. In general, correct C++, but still wrong.

Instead of discovering all of this yourself, you can invest some time in reading best practices books. This of course goes for all languages and processes, but I think it is especially important for C++, being such a complex language, and being one of the few remaining big languages lacking a garbage collector.

Effective C++ gives you, as its full title promises, 55 Specific Ways to Improve Your Programs and Designs. These are further grouped into nine chapters that deal with related topics. Each item ranges from one page for the simple ones, to ten pages for the more involved. They all include, and tend to start with, example code, followed by a discussion of what is wrong with it, and conclude with a better way. I find this to be a good pedagogical approach, and it is indeed one I strive to follow on this blog.

Meyers start out with the simple stuff, such as recommending the use of const whenever possible. This is is simple tip by the sound of it, but he actually uses a full nine pages to cover the topic, const being such a versatile keyword. He moves on to other well known tips like preventing exceptions from leaving destructors (which I also covered briefly while elaborating on function try blocks) and keeping data members private, but also touches on more complex topics, like object oriented design in C++, the proper use of overloaded operators and keywords, and generic programming.

For a full list of chapters and items, please use the magic of the fabulous internet.

The book has four and a half stars on Amazon, which I definitely think it deserves. You do however need some experience with C++ to appreciate it, and indeed to understand some of it. I would not recommend it as follow up to a short university course about C++, or after reading an introductory text to the language, but if you have been programming C++ actively for some time, it is a rewarding read. Even if you have written C++ for many years, I am sure there is new stuff to learn in there.

If you enjoyed this post, you can subscribe to my blog, or follow me on Twitter.

2 Responses to “Book Review: Effective C++ by Scott Meyers”

  1. Urfoex Says:

    You a quick note:
    using -Weffc++ with g++ will show some warnings specified in this book.
    “-Weffc++ (C++ and Objective-C++ only)
    Warn about violations of the following style guidelines from Scott Meyers’ Effective C++ book:

    Item 11: Define a copy constructor and an assignment operator for classes with dynamically allocated memory.
    Item 12: Prefer initialization to assignment in constructors.
    Item 14: Make destructors virtual in base classes.
    Item 15: Have operator= return a reference to *this.
    Item 23: Don’t try to return a reference when you must return an object.

    Also warn about violations of the following style guidelines from Scott Meyers’ More Effective C++ book:

    Item 6: Distinguish between prefix and postfix forms of increment and decrement operators.
    Item 7: Never overload &&, ||, or ,.

    When selecting this option, be aware that the standard library headers do not obey all of these guidelines; use `grep -v’ to filter out those warnings. “

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: