Effective C++, Third Edition 296
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.
Object-oriented design patterns. A necessity! (Score:4, Insightful)
Re:Object-oriented design patterns. A necessity! (Score:3, Informative)
Re:Object-oriented design patterns. A necessity! (Score:2)
char const *ptr = "abc";
puts( const_cast(ptr) );
Re:Object-oriented design patterns. A necessity! (Score:2)
What you really want is the library developer to be const correct with the
I only have one book on programming (Score:2, Insightful)
Re:I only have one book on programming (Score:3, Funny)
Re:I only have one book on programming (Score:5, Informative)
The book the parent is talking about is here http://www.amazon.com/exec/obidos/tg/detail/-/013
Re:I only have one book on programming (Score:5, Insightful)
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.
try objC (Score:3, Interesting)
So I set about porting my C++ libraries to Objective-C, and haven't looked back since. In ObjC they are smaller, cleaner, leaner, and meaner.
Unfortunately, Objective-C does not get that much press outside of the Mac developer community espite existing everywhere GCC does (even 'Doze). Being essentially C plus a runtime and a few syntactical extensions, it is probably closer to plain C
Re:I only have one book on programming (Score:2)
For all intents and purposes C++ is a superset of C (ignoring C99). So, how can be C++ more painful to program in?
Show me C-code, which cannot be used in C++ (excluding with the most trivial changes, like dynamic arrays to std::vector).
Then try to realise the C++ code which Alexandrescu showed in "Modern C++ Design" in C and compare the results.
Heck, even if I'd have to program purely imper
C++ is pretty freakin' ugly... (Score:2)
"For all intents and purposes C++ is a superset of C (ignoring C99). So, how can be C++ more painful to program in?"
If you just want to use C++ to write C, well then yes that's correct. But then why bother with C++ at all in that case?
Speaking as someone who's been scrawling code in C++ ever since that 1st-edition abomination of a manual was written by Stroustrup (gah! 19 years ago?!?), C++ has some great features for implementing OOD. But it also has some incredibly ugly areas as well, add-ons stuck
Re:C++ is pretty freakin' ugly... (Score:3, Insightful)
One can use function overloading, operator overloading, classes, templates, multiple-inheritance, when one wants to. Each single of them. But one doesn't have to.
Yes, all those things can make your code more complicated, but they can also make your code easier. The question is, whose fault is it, when the first happens?
It is all a matter of me making a (hopefully) intelligent and educated decision at each point in the code. And if sensible, one can e
Re:I only have one book on programming (Score:2)
I recall... (Score:2)
once upon a time (before the development team fixed the bug) c+=c+++++c; to be perfectly valid
Re:I recall... (Score:2)
sorry about the prev. post (Score:3, Insightful)
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.
Eh? (Score:2)
Re:sorry about the prev. post (Score:2)
Re:sorry about the prev. post (Score:2)
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
Re:sorry about the prev. post (Score:2)
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.
Re:I recall... (Score:2)
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);
Re:I recall... (Score:2)
Re:I recall... (Score:2)
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.
Re:I recall... (Score:2)
A compiler may perform the c++ before the ++c.
A different compiler may perform the ++c before the c++
Another compiler could switch between either method, dependent on optimisation settings or even something as ridiculous as the day of the week
Any of the above would be deemed to be correct interpretation of the language.
Do not base your knowledge on how your favourite compiler operates.
Finally some great info in a review (Score:4, Funny)
TR1 is interesting (Score:2)
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).
Pay them or pay me. Or don't (Score:2, Interesting)
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]
Re:Pay them or pay me. Or don't (Score:2)
Re:Pay them or pay me. Or don't (Score:3, Informative)
Re:Pay them or pay me. Or don't (Score:2)
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.
Re:Pay them or pay me. Or don't (Score:2)
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.
A Good Book For The C++ Newbie? (Score:2)
Re:A Good Book For The C++ Newbie? (Score:5, Informative)
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.
Re:A Good Book For The C++ Newbie? (Score:5, Insightful)
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.
Absolutely! (Score:2)
Goodluck!
Accelerated C++ (Score:2, Interesting)
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)
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.
Re:A Good Book For The C++ Newbie? (Score:4, Insightful)
by Bjarne Stroustrup
by Nicolai M. Josuttis
by Andrew Koenig and Barbara E. Moo
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.
Re:A Good Book For The C++ Newbie? (Score:2)
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
Comprehensive List of Book Reviews (Score:5, Informative)
Don't let the name of the Association mislead you, they deal with many other programming languages and subjects too.
If only C++ developers read their copy (Score:2)
-M
Does it still go to 11? (Score:2)
http://www.spcspringboard.com/Speaker%20Images/me
GCC Support for EffC++ (Score:2, Informative)
Scott Meyer's hair (Score:2)
Thinking in C++ is also a great book (Score:3, Informative)
The sad thing is (Score:2)
This is the really sad part, and even sadder is that many people don't understand why it is sad.
Get a dictionary. (Score:2)
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.
zerg (Score:2)
Re:Effective? (Score:3, Informative)
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.
EricOld stuff: The ANSI Standard: A Summary for C Programmers [ericgiguere.com]
Re:Effective? (Score:2)
But again, as someone mentioned above, often it is the patterns, in this case the OO patterns that matter not the syntax. Now my favourite OO language is Python, I hated it becaus
Re:PHP? (Score:2)
PHB (Score:2)
No, says an amazon.com review (not mine) (Score:3, Informative)
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
Re:MODS: wrong book! (Score:2)
Re:The One book (Score:2)
DO NOT go to this book if you have a question about the language, you won't find it in there. Oh it may be in there - you just won't find it. It is one of the most poorly organized programming books I've ever seen.
Re:Do people still write new C++ code? (Score:3, Interesting)
Hell, I still like C over C++, simply because I feel like I'm really in control of whats go
Re:Do people still write new C++ code? (Score:2, Insightful)
So when did C++ start running on bare hardware? Every time I've run it, I needed an OS and a huge pile of libraries. Is there something inherently worse or different about loading a VM than loading libraries?
"C++ is fully portable"
Because source code portability is so much easier than binary portability? Lets see you recompile something written for Windows on AIX and have it run the first time. I've done that in Java.
Re:Do people still write new C++ code? (Score:2)
As long as we are talking console vs. GUI, then yes...done that too. STL goes a long way towards making this not hurt so bad.
It is merely a matter of preference in most cases unless requirements raise their ugly head
Re:Do people still write new C++ code? (Score:2)
By the way, some of the games out there that require fast rendering are done mostly in Java for example IL-2 Sturmovik made by the Russian company C3 is written in java but some of performance crititical code is
Re:Do people still write new C++ code? (Score:2)
It compiles to machine code that runs on (relatively) bare hardware. It calls OS and library functions that also run on relatively bare hardware.
"Is there something inherently worse or different about loading a VM than loading libraries?"
Worse? Depends. Different? Definitely. A VM and a library are not comparable things. In terms of performance, running on a VM is worse than "bare hard
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:3, Interesting)
Nobody with even half a brain actually believes C++ is a good thing.
Oops (no pun intended), I must've lost half my brain while learning C++. There's nothing wrong with OOP when applied correctly to C in the proper situation. There's nothing wrong with C when a procedural approach is better, and in the end, C++ is often just a better C compiler.
My problem is that the book is probably *Meyers doing templates* again. When templates first came out, I was sold on the idea. Years later, it seems that in p
Re:Do people still write new C++ code? (Score:2)
Wouldn't it be neat if programs automatically closed all resources when you were done with them? It would be like a book flying back to the bookshelf when you are done reading!
Amazingly, C++ supports this with a concept called RAII (resource allocation is initialization). Your file handles automatically close for you when you are done. Your classes come and go as you need them, without needing to worry about memory yourself. Shared auto pointers work great. They are not perfect, but they solve a l
Re:Do people still write new C++ code? (Score:3, Informative)
Of course, I may simply be feeding a troll here (a slashdotter misspelling "perl"? Come on!).
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2)
(note: gcc tends to optimize poorly, especially old versions icc often optimizes to as
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:3, Insightful)
Maybe it's because some of us are writing software for the real world?
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:3, Insightful)
Re:Do people still write new C++ code? (Score:2)
You must be kidding. Why right off the bat you have Azureus and Eclipse written in Java.
Yup 2 whole cool apps written in Java. Other than that? Well, err... let's see. Oh, I got it! Business Enterprise applications!
Whoo boy what fun! Hundreds of different ways to move large quantities of money from point A to point B for corporations providing services of questionable benefit to mankind. Just thinking of developing one of these suckers makes me want to kill my
Re:Do people still write new C++ code? (Score:2)
Only if you get to move large amount of money from A to B, except a small amount going to C (your account).
If not, I'll happily keep my embedded system projects, thank you.
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2)
However, I'm not aiming for HIGH, but PREDICTABLE performance.
You take a look at a loop and you'll roughly know how long it's going to take to run for C++ without GC.
Until Java or C# supports true destructors (i.e. I should be able to tell the GC that I want to delete this object whenever I want, not the GC want), a lot of people, myself included, will not use it for systems programming.
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:3, Interesting)
1) OS dependent on VM
2) VM needs OS to load
3) Lather, rinse, repeat
Re:Do people still write new C++ code? (Score:2)
Re:Do people still write new C++ code? (Score:2, Insightful)
Re:Do people still write new C++ code? (Score:3, Interesting)
And the ones that don't still require a runtime. I would actually switch to Java for a lot of things if I could get one that would compile to native code and didn't require anything more than a standard libc.
And as far as the Java device driver, check out...
Except that it doesn't run on my OS. It doesn't run on any of my friends' OS. Heck, it doesn't even run on Sun's OS, and they own Java! JavaOS is like the Lisp Machine: It's a ni
Re:Do people still write new C++ code? (Score:4, Insightful)
The reason why there are so many people around saying we should use Java and C# is ignorance. These people have never had to write code where performance matters. I work on a large graphics application that uses Python bindings to make it easy to use. But we still have to develop non-Python part using a language whose performance doesn't suck beyond belief. If we don't, then the competition will be faster.
At this point I usually have to endure the lecture about how slow code can be speeded up with good algorithms. But we have some of the best people in the field working on our algorithms and still need more speed. There is no choice but to use C++.
Re:Do people still write new C++ code? (Score:2)
The Java Advanced Imaging API in the JDK offers a C-based library called mediaLib that accelerates the imaging functions because the pure Java versions can't achieve good performance.
Sun would never say this publicly but internally they recognize that Java can't achieve the performance of good optimized C code.
Re:Do people still write new C++ code? (Score:2, Informative)
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++).
Re:Do people still write new C++ code? (Score:2)
well designed and coded versus language are two entirely different concepts. any well written program will run better than a poorly written one. period. we tend to think of java as slow, but it's the gui (swing) that's slow. as for java itself, comparing two comparable algorithms, there is little difference. now, why would i choose java per se over c++. here's an example: in my AP Comp Sci class, we created a swin
Re:Do people still write new C++ code? (Score:2)
Re:Amazon link. (Score:3, Informative)
Amazon: $44.99
Bookpool: $34.95
Re:If a language needs a book this thick, (Score:2)
Re:If a language needs a book this thick, (Score:2)
I'm sorry, I really don't get the connection between simplicty and tinkering. Pure lambda calculus is almost the simplest programming language imaginable and yet there is a vast published literature on the tinkering people have done with it. In fact, when I'm in the mood for tinkering I play with a nice clean and simple language like Haskell. You can spend years and publish reams of papers tinkering to find the optimal way to reimplement even the mos
Re:If a language needs a book this thick, (Score:2)
Sure you can do calculus with a 20 page set of rules, but not very efficiently. The core language does contain rather more than C or Smalltalk, the templates being a beast. But it's a beast that makes it easier to write efficient code and allows for meta-programming. BTW, why are you comparing Smalltalk to Jav
Re:This is a 2 (TWO) sentences book! (Score:2)
Re:This is a 2 (TWO) sentences book! (Score:2)
Re:Effective C++ (Score:2)
Re:Effective C++ (Score:2)
Re:In keeping with the other recent stories... (Score:2)
Re:In keeping with the other recent stories... (Score:2)
In Soviet Russia, Netcraft would confirm that Scott Meyer poured hot grits down Natalie Portman's pants.
Jokes on slashdot live forever...
Mozilla Firefox/KDE?! (Score:2, Insightful)
I'm sure the Firefox and KDE folks don't need your pity.
Re:I've done absolutely zip with programming.... (Score:2)
No. In fact C++ would not be good for you. I recommend learning Python. Powerful enough for websites and databases. It tries to force you to write good code. I've also heard good things about Ruby, from programmers I trust, that is the only other option worth considering.
C and C++ are great for performacne counts, low level things. However they are not what you want when creating a web site. You can do it, but it will take 10 times as long to make your website. (If anything it will be worse t