Lurker News
Do you have some good advice or know any useful resources to learn in a proper way how to code in C++? For the context, I know some C, but C++ seems a different kind of beast, and it's easy to get lost in the huge variety of features and libraries it offers.

Comments (173) 47 threads

Show all comments

Showing thread 7 of 47

isaachier3 replies#
IMO, the classic C++ book/author is still the best: Effective C++. Don't forget about the sequels, including the mostly overlooked Effective STL (which I happen to like better than the first two books). And to address the modern part of this question, I'll add that Scott Meyers has written Effective Modern C++ as well, but I'd read that last after getting the hang of C++03. No matter what people say, I tend to believe C++11 and on is not really a different language as much as it is syntactic sugar to cover up the ugliest parts of C++.
dfan3 replies#
As someone who programmed in "classic C++" for decades, I feel like modern C++ is pretty different, and that it's not just syntactic sugar to make some ugly things easier. The biggest example is that my natural inclination to use raw pointers everywhere and manage all memory myself, while idiomatic modern C++ is full of unique_ptrs and shared_ptrs everywhere, and raw pointers seem to be regarded as a code smell. Converting to this style is not an automatic process.

For people who are coming from a classic C++ background, I find Bancila's Modern C++ Programming Cookbook to be a good first stop for discovering modern C++ idioms.

jcadam#
I remember being placed on a C++ project for a few months after having been away from the language for almost 10 years. The lack of raw pointers was an immediate slap in the face and had me going "WTF am I looking at?"
isaachier#
OK from that perspective I can relate. Even before using C++11 I was using a lot of the new STL through Boost. If you use Boost, the only fundamental differences are syntax like auto, variadic macros, constexpr, noexcept, and lambdas all of which are familiar enough to get by. The only practical differences that have no equivalent in C++03 is move operations and maybe the threading/chrono stuff. Effective Modern C++ covers that so that's all I needed to "upgrade."
AstralStorm#
I suppose you shouldn't be using pointers if not required, not even smart(er) ones.

They are not free and prevent certain kinds of optimization as well as allow accidentally sharing state.

ahartmetz3 replies#
IMO, Effective C++ is just a collection of warnings about pitfalls, something that is unfortunately needed for C++ programming, so do read it. But it is neither an introduction nor a collection of big picture advice.
dfan1 reply#
I usually recommend Effective C++ as the C++ book that everybody should read second. I'm still not sure what the best book to read first is, though...
lfowles#
Probably Tour of C++ if you're already familiar with older C++. (Or just get the book it's taken from, C++ Programming Language 4th Ed.)
ape4#
I picked it up to learn modern C++ and was totally confused. Use xxx instead of yyy. Er, what's xxx and yyy?!
isaachier#
That is arguably true for the first two books, but Effective STL is very opiniated. Scott Meyers argues not to use for loops when possible and to use the algorithm library everywhere instead. I tried convincing my team to do this but we were using C++03 and writing a struct functor is no fun... I think in C++11 a for loop and even a for each loop should be modernized with a good lambda instead.
emmelaich1 reply#
It's a pity that one of the most recommended books is about the pitfalls of C++ and is by someone on his own admission has never written production C++ code.

Of course it's a very good book though.
My recommendation is for "Accelerated C++" by Koenig and Moo. It's rooted in actual teaching experience and compared to most C++ books is pretty slim.
The only negatives these days is that it is a bit old and (still) expensive.

shaklee3#
Even more of a pity that Scott Meyers has retired from c++ and won't be writing any more books.