Is effective C++ still effective?

2019-03-07 15:28发布

问题:

From what I saw in this post I decided to start reading the book Effective C++.

But now that there are many new features because of C++11 and that a few of the good practices changed, I'm not sure whether or not it is actually a good idea. Has the advent of C++11 deprecated any of the advice contained in Effective C++? If so, which topics should I avoid?

回答1:

This what Scott Meyers himself had to say about it on his own blog

Which may lead you to wonder whether the information and advice in this pre-C++0x edition of Effective C++ remains relevant. I'm pleased to report that it does. Surprisingly so, in fact. Having spent nearly two years steeped in the details of C++0x, I expected to groan a bit as I reviewed this book's table of contents with C++0x in mind. Surely some Items would be inappropriate. But the advice I found proved sound. Should C++0x developers prefer consts, enums, and inlines to #defines (Item 2)? They should. Should they prevent exceptions from leaving destructors (Item 8)? Certainly. Should they use objects to manage resources? Declare data members private? Consider alternatives to virtual functions? Factor parameter-independent code out of templates? (Items 13, 22, 35, and 44.) Yes, yes, yes, yes! My goal has always been for Effective C++'s table of contents to summarize the advice in the book, and that summary remains just as applicable to C++0x development as to “traditional” C++ development. C++0x is a bigger language, and in some ways it's a different one, but the core techniques for making effective use of “old” C++ are core for the effective use of C++0x, too.

This doesn't mean that this Effective C++ is a perfect match for C++0x. The book doesn't discuss features new to C++0x, so Items about making effective use of those features are missing. A C++0xified Effective C++ would certainly have Items devoted to move operations, to uniform initialization, and to lambda expressions, and it'd probably have an entire chapter on making effective use of the concurrency API. Such a book would also contain different examples, e.g., ones making use of auto variables, range-based for loops, in-class default initializers, as well as the occasional variadic template. To the extent that this book falls short in its support for C++0x, the errors are those of omission, not commission.

UPDATE: the new title Effective Modern C++ has been for sale since November 2014 from O'Reilly and Amazon (and many others that you can google for).



回答2:

Yes, definitely still worth reading. There is a new book that Scott is working on: Effective C++11, which concentrates on C++11 only code. The Effective C++ is still very relevant, and is not superseded by the new book. Buy it, read it, enjoy :)



回答3:

One, the book is still of course valid for C++03.

Two, Meyers is writing or has written, depending on when you are reading this sentence, Effective C++11.

Three, speaking in generality, the points of this book will still be valid. C++ still favors speed over safety, and many issues in Effective C++ revolve around this.

The only kind of point I would expect to be invalid are ones that say "Don't do this, do this instead." "Dont' do this" will still be valid. But C++ will have solved some problems. In particular, any recommendations to use boost are likely deprecated, as C++11 has included many of the features Meyers specifically refers the reader to Boost for.