Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Programming Books Media Book Reviews IT Technology

Effective C++, Third Edition 296

nellardo writes "If you've been programming C++ for any length of time, you probably have the book, Effective C++, by Scott Meyers on your shelves. Well, this book has just hit its third edition, and it's a major re-write and re-org. Do you need this book? If you program C++, yes, you probably do, even if you have a previous edition. Don't let the "Third Edition" faze you, because it has lots of new insights into the vagaries of the C++ language. And if you're new to C++, this is pretty much a must-own book." Read on for the rest of Nellardo's review.
Effective C++, Third Edition
author Scott Meyers
pages 297
publisher Addison Wesley
rating 9/10 for C++ programmers; not worth it otherwise
reviewer nellardo
ISBN 0321334876
summary Re-write of standard second book on C++

C++ is a large and complex language, and always has been. That's what made the first edition of Effective C++ so useful. What began as a simple concept of "C with Classes" grew as time went by, developing quirks and foibles that made sense only once you understood a great deal about what was going on. The first edition provided short, digestible synopses of the best practices of quality C++ programming. Even people that had been programming C++ for years could read the book and pick up something new.

That was 1991. A lot has changed in C++ since then. For instance, templates were only just being developed as an addition to the language, and most C++ compilers simply generated C code. Now, in 2005, C++ has gotten a great deal more complicated, and C++ templates have turned out to be a programming language in their own right. Exceptions, the Standard Template Library, threading libraries, and a wealth of truly inventive programming have turned C++ into an amalgam of concepts and mechanisms from essentially every programming language under the sun (ahem). C++ isn't quite as complex as Ada, but that's a much tougher case to make today than in 1992.

In addition, the understanding of what the best practices actually were has changed. Indeed, common tricks from 1991 are now generally frowned upon. In 1991, a friend function was common in code examples. For instance, operators were routinely declared as friend functions. Now, in 2005, friend is seen as creating the tightest coupling possible between components, and is often avoided. What happened?

This is where the book's background starts to shine. Item 1 is "View C++ as a federation of languages." Meyers does a clear and cogent job of decoding broad swathes of C++, explaining C++ as a multi-paradigm tool, and placing language features in different paradigms. Change paradigms and the guideline for what makes for effective C++ changes. This is a hard case to make, but he manages to do it in accessible language even a newbie to the language should be able to follow. Experience from 1991, 1997 (the second edition, mostly a spruce-up job of the first), and now add up to explain the boundaries.

Like earlier versions of the book, the final items provide a good hint on how to keep current. Item 54 is "Familiarize yourself with the standard library, including TR1", and Item 55 (the last) is "Familiarize yourself with Boost." Both of these point to the two places C++ is most likely to grow in the near future, TR1 being essentially done, and Boost being an active source of new things likely to make it into future language extensions.

While 55 items isn't as neat as 50 items, the items in the middle still provide a good place to start for a new C++ programmer. The experienced C++ programmer (the kind who's running around their department suggesting simply using Sutter and Alexandrescu's C++ Coding Standards as the department's new coding standards as is) may not get as much from the book, but it isn't really looking for that programmer. It is advertised as a "second book" on C++, and that's exactly what it is. Buy your textbook to learn from, then buy this book.

Can the experienced C++ programmer get something from the book? Sure, but it's more along the lines of having a handy way to explain to the new guy in the next cube why you want to make sure exceptions never leave a destructor (Item 8) rather than having to figure out a clear way to say it yourself. If nothing else, the more experienced programmer may want to read it just to know what the new guy is likely to ask about.

As a book per se, it's nicely done. It uses color judiciously, mainly to point out the most important parts of the code examples. It also includes lists of items from More Effective C++ and Effective STL, which are handy, albeit blatant plugs. More interestingly, it includes a map from the items in the first edition and the second edition to the items in the third edition (in both directions). This makes it clear that this book truly is a substantial re-write. I would have liked to see a list of all the items, along with the two or three bullets that summarize them as a separate table (maybe on the front inside cover for easy access), but that's a minor point.

All in all, Effective C++, Third Edition is exactly what it claims to be. A significant re-write of the best second book out there. Learning C++? Then pick it up. Using C++ actively with a bunch of other programmers? Pick it up. Not using C++? Don't bother.


You can purchase Effective C++, Third Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Effective C++, Third Edition

Comments Filter:
  • by CyricZ ( 887944 ) on Wednesday June 08, 2005 @03:18PM (#12760739)
    One of the strong points is its discussion of object-oriented design patterns. These days OO design patterns are just as essential as iteration when programming in languages like C++. But unfortunately, many C++ books fail to mention such patterns, and how they can be used to help make software development quicker, more efficient, and more resistant to errors.
    • Does the book discuss const correctness? I am always annoyed, when using a library written by someone else, if they don't const things like char* variables that aren't getting changed. It makes you either have to not const your own code, or copy to a non-const array (i.e., extra code and poor performance).
      • If you know the library function isn't going to modify the object, use a const_cast:

        char const *ptr = "abc";
        puts( const_cast(ptr) );

        • That only works if you know for certain that they're not modifying the object for some obscure reason in the other function. Usually you're pretty sure, but you don't know absolutely. if you're wrong, your const assumptions throughout your program are all ruined - i.e., you might as well just remove all of your const declarations, because they could be lying to you. Duplicating your array is the only way to ensure that they're not.

          What you really want is the library developer to be const correct with the
  • The only book I own on programming is ANSI C :p
    • What made C so hard for you that of all languages you needed a book for just this one?
    • by Paralizer ( 792155 ) on Wednesday June 08, 2005 @03:30PM (#12760859) Homepage
      Great book, I have it too. It's perfect for reference if you're having one of those horrid brain cramps, but it is nothing to learn from IMO. If you're just starting out grab another book, the one the story is talking about looks interesting. I'm not much on C++, but it looks great for those of you who really want to get a foothold on the language. Of course, even if you know C++ it's always helpful to try out pure C too.

      The book the parent is talking about is here http://www.amazon.com/exec/obidos/tg/detail/-/0131 103628/qid=1118258760/sr=8-1/ref=pd_csp_1/102-7661 598-1944930?v=glance&s=books&n=507846 [amazon.com], C Programming Language (2nd Edition) by Brian W. Kernighan and Dennis Ritchie, the guys who created the language.
    • That's a shame. See (pun), no matter how much you like it, and no matter how 1337 it makes you, there is much more to programming than ANSI C.

      Do you know any functional languages? Can you (intelligently) debate Perl vs. Python? Do you know why Fortran can be much faster than C? Do you believe that a virtual machine can be faster than assembler? If you said "no" to any of those, yet refuse to look past your C knowledge, then you're depriving yourself of a lot of good learning.

      There's a vast difference between "I haven't gotten around to it yet" and "I've already solidified my way of thought". You seem to take pride in the latter, and for that I feel sorry for you.

  • (A bit off topic but...)
    once upon a time (before the development team fixed the bug) c+=c+++++c; to be perfectly valid :) It was a mighty looking statement.
    • Your C++ grammar is impeccable, and I'm sure you have a funny story to tell, but your English is so unparsable I can't tell what you're trying to say. Could you say it again?
      • (the correct version ;) )

        Once upon a time:
        c+=c+++++c;
        was a perfectly valid statement in the project.

        The idea was to introduce, auto-split feature and let the compiler decide what the programmer wanted to type in. This would have saved programmers time and make them more productive. (Dreams, o marketing dreams).

        But, how do you deal with something as:
        a+= b+++c;
        is it:
        a+= b++ + c;
        or is it:
        a+=b + ++c;

        It took 2 hour meeting (with 4 people) to convince the newly appointed marketing guy to leave the idea.
        • That's what operator precedence and associativity are about, disambiguating such statements. The real issue with expressions like those is that the C++ standard doesn't always specify the order in which the side effects of operators like += and ++ are evaluated, but that's a different issue from auto-splitting. (Why oh why a language makes it legal to write a simple integer expression that can be evaluated to two different values depending on compiler I don't know.)
        • But, how do you deal with something as:
          a+= b+++c;
          is it:
          a+= b++ + c;
          or is it:
          a+=b + ++c;
          There are two things that need to be said to anyone who feels the need to ask that:
          1. Learn the rule of maximal munch [devx.com]
          2. If you ever write code like that in my project, you're fired.
        • I'll tell you how you deal with code like that. You don't write it. Meyers talks about this in his books : mean what you say and say what you mean. Just because C++ ALLOWS something doesn't mean you should write code like that. At ANY C++ shop I've worked at in the last several years, code like you listed would get you cock-punched in a hurry.

          There's no reason to be cute just to write hard-to-read code, and it pisses me off to no end when people use examples like the above on why C++ is a bad programming

        • Once upon a time:
          c+=c+++++c;
          was a perfectly valid statement in the project.


          This is always invalid C++. The resulting value of c is undefined.
    • That one's great ;) And in theory, you could have chained them:

      c+=c+++++c+c+++++c+c+++++c+c (etc). That would make a nice border in an obfuscation contest.

      My favorite obfuscation technique is sticking the little-used comma operator where people don't expect it. For example:

      int a,b;
      a=123,456 - 123,455;
      printf("%d\n",a);
  • by Anonymous Coward on Wednesday June 08, 2005 @03:20PM (#12760764)
    Just from reading the front page, I've learned that Effective C++ may be more useful to C++ programmers than those of other languages AND that the "Third Edition" may contain new insights not found in the previous editions. Slashdot needs more reviews like this.
  • I've nearly given up on C++ as an Effective language. But...
    TR1 is interesting. C++ may be useful again in 2-6 years (time for TR1 to become semi-standard, and for major compilers to accept it).
  • You can purchase Effective C++, Third Edition from bn.com.

    With a small commission for OTSG. Kind of unethical to take a commission for a book you're reviewing. Alternatives: Use my Amazon link [amazon.com], which is blatant spam on my part, but a tad more ethical, since I don't make any claims about the quality of the book. (Besides, I need the money more than they do!) Or you can feed the ISBN into Wikipeia [wikipedia.org], and find various libraries and booksellers that have the book. Finally, you can just feed the ISBN to Googl [google.com]

    • What, why is this not ethical? Are you assuming he *lied* in the review to get people to buy the book?
      • In journalism, it's considered unethical to pretend you don't have an interest or bias, even if you honestly believe you're writing objectively. Full disclosure is enough to resolve this ethical problem -- and Slashdot is usually pretty good about such things, revealling that Slashdot is owned by OSTG whenever they report on an OSTG-owned company. But they really should reveal that they have an interest in people buying the book. Either that, or just not provide the buy-me link.
      • What, why is this not ethical? Are you assuming he *lied* in the review to get people to buy the book?


        It doesn't matter if he lied or not. One rule of journalism is full disclosure: if you have a personal or financial interest in what you are writing about, you are required to inform your audience about it. Otherwise the line between reporting and shilling becomes very thin.

      • What, why is this not ethical? Are you assuming he *lied* in the review to get people to buy the book?

        Conflict of interest - he has a vested interest in getting you to buy the book, not present a balanced review. In this case, I don't care, as it's not a big thing.

  • I just finished a college course in intro C++ programming. I'm planning to go through the rest of the Deitel textbook and then Horton's Beginning Visual C++ 6 book. Would Effective C++ be a good follow up book or should I look elsewhere?
    • by SnowDog_2112 ( 23900 ) on Wednesday June 08, 2005 @03:44PM (#12760997) Homepage
      I haven't done C++ programming for almost 5 years, but for five years before that I was developing exclusively in C++.

      Effective C++ (an earlier edition, obviously) was a huge boost to my early years in the workplace.

      It was pretty much required for every new hire to pick it up, our coding standards referred to it, and you were expected to have it nearby if you were messing around with the codebase.

      It is full of no-nonsense vital explanations of C++ best practices. If you're going to break a rule from this book, you should be able to explain why you're going to do it :).

      I still have it in my bookshelf "just in case" I ever am faced with a C++ question.

      Is it a good book for a newbie? I don't know. But it'll help you understand how not to make newbie mistakes, that's for sure.

      If all you're writing are toy programs, heck, it still might be interesting as just good background knowledge. But if you're developing professional software, it will help you make your software more solid and more maintainable.

      And no, I don't know the author or anything. I just loved this book.
    • by Brandybuck ( 704397 ) on Wednesday June 08, 2005 @03:47PM (#12761023) Homepage Journal
      Dump the VC++ book. It's not about C++, it's about an IDE and API.

      p.s. If you want an API book, buy "GUI Programming with Qt" instead. It comes with a free copy of Qt noncommercial for Windows. Your programs will be crossplatform and trivially portable to Linux, Unix and OSX. The quality of the Qt API makes MFC drop to its knees in humble supplication.

      p.p.s. If you want to learn the VC++ IDE, read the help pages.
    • I've been programming in C++ for almost ten years. His books are one of the best in the market. I prefer it over Strousup's book. The CD is awsome. Some of the stuff may be a little over your head at first, but stick with it. He has tips on developing not only good C++ programming habits, but also good overall OO programming habits. This will help you when you get into other OO languages.
      Goodluck!
    • Accelerated C++ (Score:2, Interesting)

      by devphil ( 51341 )


      By far the best book I've ever seen for beginners, or relative beginners, is Accelerated C++ [acceleratedcpp.com]. The authors have been involved in C++ since its inception and have been teaching it ever since as well.

      • Re:Accelerated C++ (Score:2, Informative)

        by mariox19 ( 632969 )

        Before buying that book, I would suggest a person sit down and at least read a chapter. I have that book. While I'm sure its approach appeals to some people, I found it overly pedantic. It was a little like sitting through a boring lecture.

        As always, your mileage may vary.

    • by foo fighter ( 151863 ) on Wednesday June 08, 2005 @05:02PM (#12761859) Homepage
      Their are four or five books I've found to be the standards that should be on any C++ coder's bookshelf:
      • The C++ Programming Language (Special 3rd Edition)
        by Bjarne Stroustrup
      • The C++ Standard Library : A Tutorial and Reference
        by Nicolai M. Josuttis
      • Accelerated C++: Practical Programming by Example
        by Andrew Koenig and Barbara E. Moo
      • Effective C++: 50 Specific Ways to Improve Your Programs and Design (2nd Edition) and More Effective C++: 35 New Ways to Improve Your Programs and Designs by Scott Meyers


      Stroustrup is the reference book for the language. It could be used as a textbook or tutorial since it has good pedagogy and problems to solve at the end of each section. But Koenig and Moo is better for the tutorial aspect and Stroustrup is better as a reference. Their is a paperback version of the 3rd edition, but the special edition, with its stiff spine and ribbon bookmark, is worth the money because you will be frequently referring to it.

      Josuttis is the reference to the standard library and standard template library. This is an advanced book, and could probably be the last one of these you purchase. He covers everything the C++ standard library has to offer, especially including templates. Don't worry about these too much as you start out. Stroustrup and Koenig and Moo both touch on these topics and give a gentler introduction.

      Koenig and Moo is the tutorial that every C++ programmer should start with, IMHO, and should be the standard intro university text. It doesn't carry baggage from other languages or bad style. Even though you've gotten through Deitel, I'd suggest going through Koenig and Moo next, skipping Horton completely.

      Meyers two books used to be the standard on best practice. I guess this new 3rd edition, of which I was not aware, is the new standard. There are some things you can do in c++ that you shouldn't do, as well as some pitfalls that can be avoided if you are aware of them. Meyers points these out and is essential to creating strong code. I would get the new 3rd edition of Effective C++ and wait on More Effective C++ until it comes out in 3rd edition.

      To sum up: Go through Keonig and Moo first to learn the language, but get Stroustrup at the same time to use as your reference. Pick up Myers 3rd edition when you finish Keonig and Moo, then start working through the problems in Stroustrup. As you get to the advanced sections of Stroustrup, pick up Josuttis to use as an additional reference. When you've finished all of these you should be very well versed in c++ and a better c++ programmer than probably 80% of the coders out there.

      If you are done with school and out there working, you should be able to get through these in about a year of independent study. If you are still in school, focus on the classes you are paying for, and use these books as outside reading and references to inform your classwork.

      Some other books to check out:
      The C Programming Language by Brian Kernighan and Dennis Ritchie and The C Standard Library by P.J. Plauger. This is actually a great place to start learning to program, since you work very close to the hardware, but in a much more portable fashion than assembly.

      Code Complete, Second Edition by Steve McConnell and The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt. These contain essential knowledge about being a programmer beyond the nuts and bolts of the code. Reading these and applying the knowledge to your work will take you into 90% territory.

      I hope you found this useful and that this helps guide you to where you want to be.
      • The C++ Standard Library : A Tutorial and Reference
        by Nicolai M. Josuttis


        (Current editions) A good book for sure, but don't try to buy it cheap second hand and end up with an early printing. I have a 3rd printing, January 2000 and the errata runs to 9 solid pages of printed A4.

        The mistakes are missing references ('&' symbols) to argument modifying functions (!), completely wrong syntax for template defintions, and classics such as replace "getline() ignores leading whitespace" with "getline() does no
  • by turgid ( 580780 ) on Wednesday June 08, 2005 @03:36PM (#12760927) Journal
    A wise and learned former colleague pointed me at the Association of C and C++ Users book reviews [accu.org] when I asked about getting a modern C++ book.

    Don't let the name of the Association mislead you, they deal with many other programming languages and subjects too.

  • One of those books that many people had on their bookshelf, but it seemed, rarely read... given the mediocrity of C++ knowledge that I constantly ran into during my day.

    -M
  • I always thought that the pic that scott put on the books make him look like a lost member of spinal tap

    http://www.spcspringboard.com/Speaker%20Images/mey ers-big.jpg [spcspringboard.com]
  • I think the flag in gcc is -weffc++. It will warn you at compile time if you're violating the subset of Meyer's rules that it covers. :) > man gcc ... -Weffc++ (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.
  • I like this book, except for the picture of the author. His hairdo is downright creepy.
  • by bhalo05 ( 865352 ) on Wednesday June 08, 2005 @05:33PM (#12762149)
    I'm surprised no one mentioned (perhaps I've missed it?) Thinking In C++, by Bruce Eckel. It explains every subject in a very clear manner, providing quality examples throughout the two volumes. Not only that, you can download the book for free from http://mindview.net/ [mindview.net]
  • And if you're new to C++, this is pretty much a must-own book.

    This is the really sad part, and even sadder is that many people don't understand why it is sad.
  • ...Effective C++...

    That's the best oxymoron I've seen all day! Heck, I thought Microsoft Works was a good one. But now I realize that if you want to find out what an oxymoron is, you'll have a real problem, because if you look in the dictionary, the definition is: Effective C++.

    Speaking of which, did you know that naive is not in the dictionary? You: Get a dictionary, find out what this 'closure' is.

  • Does the release of the 3rd Edition mean they'll update the -Weffc++ switch for gcc?

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...