Please create an account to participate in the Slashdot moderation system

 



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:
  • Re:Effective? (Score:3, Informative)

    by Eric Giguere ( 42863 ) on Wednesday June 08, 2005 @03:21PM (#12760778) Homepage Journal

    An obvious troll, but... if you are interested in Java, check out Joshua Bloch's Effective Java [amazon.com], written in the same style as Effective C++. Great book for similar reasons.

    Eric
    Old stuff: The ANSI Standard: A Summary for C Programmers [ericgiguere.com]
  • 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.
  • This book is written in the way creator Bjarne Stroustrup sees his language and how his language should be used. This book is not thin on material for the intermediate to advanced C++ software engineer.

    One word in warning to potential buyers: You better be sharp with your STL skills before reading this book. Stroustrup writes his implementations around the STL which is not covered from a tutorial style in this book before he introduces it, which tells you that he meant for this book strictly as a reference not as a readers book. This critism is constructive, not disruptive, but I have been programming in standard ANSI/ISO C++ for 9 years, this book is best understood if you read the following first, if not, this book for even an itermediate C++ program cannot be digested to the fullest and you will reading this book fooling yourself of how much knowledge you have attained, when in reality, all that you have accomplished is reading this book so that you can say that you read Stroustrup, which is foolish, so read these first:

    1) C++ Primer 3rd Edition: Stanley Lippman Addison Wesley Books Strengths: If you are starting out with C++ with no C++ experience, this book covers every facet beginner to advanced topics, such as fundamental classes, class design covering nested class and intense class scoping rules, which Stroustrups book does not cover, there is no reference to nested classes and access privileges with nested classes with Stroustrup's book. The chapters on function templates and another chapter on class templates are the most complete and thorough beyound what you need to know for richness is explained brilliantly and better than scant coverage in Stroustrup's. The C++ Primer is long though, so if you want to learn C++ the right way, skills like this take time and effort, there is no free lunches here, but this is regarded as the best C++ book regardless of level: starter, intermediate, or very advanced master. It also serves a robust reference. This books covers the STL containers well in its own chapter and also two chapter on all the STL algoritms, plus an extended alphabetically ordered repitition in type out of the book and compile form. This book is not for the faint hearted or lazy, if you are ambitious, this book will make you a C++ king. Also get its companion C++ Answer book with all answers to the books exercise questions from author Clovis L. Tondo, also an Addison Wesley title.

    2) C++ Algorithms 3rd Edition by Robert Sedgewick also Addison Wesley books. Why? You seriouly have to know your date structure skills, linked lists, stacks, trees, queues and its accompanying algoritms, such as: searching and sorting, merging and merge sorting. Stroustrups books assumes you know how these all come together, if you do not believe this, then look at his stark and algorithmically complex data structure examples, once this is read everything will be a piece of cake, believe this, do not fool yourself.

    3) The C++ Standard Library Tutorial and Reference from Nicolai Josuttis, from Addison Wesley also, this book is the defacto bible on mastering the STL, which covers brilliant chapters on containers( vectors, lists, maps, sets, deques, and much more ). It also covers a huge chapter on standard IO streams, at least over 150 pages on this alone, as well a masterful chapter on STL strings. This should be read after Sedgewick's book. This book like all Addison Wesley books, is of the highest qualitiy and caliber of writing making it fun to read and plenty of type out of the book samples to bang in the concept. This books brilliantly also tutors you in function objects, iterators and all its variants, and STL algorithms.

    Last Word: Stroustrups book is definite worth in purchase and you cannot consider yourself a C++ software engineer, or C++ Software/Systems architect without having this book in your library, but patience and read books 1,2, and three first in that order. And wheh you do the above, and are ready to read Stroustup's book, one reminder, you must know your templates, know your templates, know your templates, also get the accompanying answer book, C++ Solutions, by Vandervoode also an Addison Wesley title.

    Good Fortune.
  • by Rei ( 128717 ) on Wednesday June 08, 2005 @03:35PM (#12760913) Homepage
    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).
  • 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.

  • by Rei ( 128717 ) on Wednesday June 08, 2005 @03:41PM (#12760968) Homepage
    A "legacy language"? Apparently it's so legacy that "modern" languages like Java are racing to implement its features [theserverside.com]. Modern C++ features like templates are really a godsend in many application development projects - check out the internal structure of ITK [itk.org] if you want a good example of that. :)

    Of course, I may simply be feeding a troll here (a slashdotter misspelling "perl"? Come on!).
  • Re:Amazon link. (Score:3, Informative)

    by Intron ( 870560 ) on Wednesday June 08, 2005 @03:43PM (#12760989)
    B&N price: $42.74
    Amazon: $44.99
    Bookpool: $34.95
  • 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 Anonymous Coward on Wednesday June 08, 2005 @04:12PM (#12761310)
    Which three books did you read? There are hundreds of books on C++ and many of them are not very good. The book mentioned in this review happens to be one of the good ones though.
  • by aurumaeus ( 673863 ) on Wednesday June 08, 2005 @04:50PM (#12761729) Homepage
    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. * 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 incre- ment 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.
  • Re:Accelerated C++ (Score:2, Informative)

    by mariox19 ( 632969 ) on Wednesday June 08, 2005 @04:54PM (#12761763)

    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 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]
  • by fm6 ( 162816 ) on Wednesday June 08, 2005 @06:14PM (#12762587) Homepage Journal
    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.
  • by 0xABADC0DA ( 867955 ) on Wednesday June 08, 2005 @06:24PM (#12762667)
    Yes, clearly machines running Smalltalk and LISP kernels [absoluteastronomy.com] never existed. And squeak developers are lying when they say its virtual machine is written in smalltalk. [squeak.org]

    And the reason why
    for (x=0; x < 10000000; x++)
    getpid();

    takes 1 second due to system call overhead instead of 0.001 seconds is because C is such a great language for operating systems... hint: it's one instruction in a "safe" OS (ie not C/C++).
  • by egoots ( 557276 ) on Wednesday June 08, 2005 @08:10PM (#12763739)

    Perhaps your googling skills need a bit o' work ;-)

    TR1 is the Technical Report (#1) on C++ Language Extensions. In other words it covers the standard library rather than the language itself.

    Try one of the following:
    Technical Report PDF http://www.open-std.org/jtc1/sc22/wg21/docs/papers /2005/n1745.pdf [open-std.org]
    Scott Myers Summary: http://aristeia.com/EC3E/TR1_info_frames.html [aristeia.com]

  • Re:I recall... (Score:2, Informative)

    by Jerry Coffin ( 824726 ) on Wednesday June 08, 2005 @11:40PM (#12765110)
    c += c++ + ++c c = c + (c+1)+(c+1) the increment operator (++) takes precedent over addition (+). So the parser (should) created the second formula above.

    You've modified c three times without any intervening sequence points, which gives undefined behavior. See http://dspace.dial.pipex.com/town/green/gfd34/art/ [pipex.com] and click on "bloopers", or just Google for "nasal demons" (honest!)

    Also note that if you don't insert spaces yourself, "c+++++c" is NOT tokenized as "c++ + ++c" either -- it's tokenized as "c++ ++" and then lexing will normally stop because what you have is illegal. Google for "maximum munch".

    --

    The universe is a figment of its own imagination.

Thus spake the master programmer: "After three days without programming, life becomes meaningless." -- Geoffrey James, "The Tao of Programming"

Working...