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

Earlier comments
vehemos#
Also in case anyone is going to suggest something project-like please something in the direction of HFT/OS/Systems related as opposed to game programming? There are loads of stuff out there for C++ related to game programming.

For OP: https://stackoverflow.com/questions/388242/the-definitive-c-...
Also some C++ related YT channels such as TheChernoProject, CppCon etc
Following the respective reddit and slack communities is also extremely helpful.
Also get your hands dirty with this: https://github.com/vitalets/github-trending-repos
or https://github.com/fffaraz/awesome-cpp There is more but this should do.
Oh I almost forgot: https://ishansharma.github.io/twitter-mentors/ http://stephaniehurlburt.com/blog/2016/11/14/list-of-enginee... https://twitter.com/sehurlburt/status/889004724669661184
Good Luck! :-)

cpfohl4 replies#
Use it.

Not being a smart@$$ here. Any language you want to learn will only become natural when you've used it for a significant project or set of exercises. Either clone or port something non trivial, or use it for your latest pet project, or get permission to use it at work.

brian_herman#
The best advice that was given to me in college on how to learn a new programming language was to use it.
kdelok4 replies#
I'd still argue that there's a lot of value in some form of teaching (via book or video or whatever). If left to their own devices, novices will often come up with messy, non-idiomatic ways to do things.
OskarS#
I find using both in combination is usually the best way to go. If you're just reading a book and doing exercises in it, you wont learn as well. Making something you want to make and using books as reference while developing makes you learn a lot quicker.

Also, the answer to this question depends a lot on your previous experience with other languages. If you're well-versed in another C-like language, jumping right in and starting to make something will probably teach you a lot, really quickly. If you're more of a beginner in programming generally, you need a book or a teacher.

murukesh_s#
Ya, I think a balanced approach is the best, begin by reaing or watching videos, but not too much, just to get an overall idea, then get hands on but don't stop there, read more code and watch more videos and continue the process for your life time!

I sometimes get carried away and stop reading more after I cross some threshold which prevented me from noticing lot of nice things like best practices that were happening in the industry/or better design patterns etc..

colmvp#
I completely agree.

Not learning from books/teaching can make it hard to improve. I love reading other peoples code and thought processes because it often reveals how I'm missing something in my toolbox.
Studies have shown that one of the best ways to remember is to take a stab at a problem before learning the solution. So even quizzes on using libraries has helped me learn methods and concepts I would have not learned on my own if left to my own way of coding. I try a simple problem on my own before learning that there is a cleaner, more efficient solution. It's easier and more approachable to do that with small problems than trying to revise an entire document of code.
Lastly, I think a lot of experts underestimate the gap between novice and intermediate, where it's really hard and frustrating to attempt things that are a bit more complicated, requiring more background knowledge than just whats shown on the surface.

piracykills#
Yeah, the trick in my opinion is to find a good enough book or guide on new features with which you can skim and familiarize yourself. If you don't understand when you might apply something, go figure that part out. Then work on a project and when it seems like you might need that concept, go read about it in more detail. In terms of real world work, having a very broad, surface level knowledge of many concepts and when you might apply them often comes in more useful than a very in depth knowledge of a few specific concepts.
3uclid2 replies#
That's a pretty useless answer. It's easy to use C++, but in a non-idiomatic or C-style way. I think the OP is aware of this problem and is looking for concrete examples of modern C++.
humanrebar#
I think reading best practices and most other forms of technical training work best after some experience is gained, even poor experience doing it the wrong way.

It's similar to why university lectures work best if the audience has already done its assigned reading. The people in the audience have better questions in mind while listening, so they can better intuit when a gap is filled in or if some part of the explanation doesn't make sense.

cpfohl#
Sure. I gathered that, but until you've done stuff the wrong way the learning isn't going to stick the same. I'm not saying _don't_ use resources, I'm saying do stuff, when it feels wrong read up on it to learn the right modern practice
stinos1 reply#
From experience I can tell you this: just 'use it' is not enough for some. I have seen truly, truly horrible code written by people who have been using C++ for decades. Let that sink in a bit, then realize that while 'use it' isn't bad advice, it is too general and too limited of a statement :P. You need to learn the right usage as well.
cpfohl#
Those people don't look for ways to improve. I am not worried about OP not trying to learn to do it the right way
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.
rambl30n#
If you know C, C++ Common Knowledge (https://www.amazon.com/Common-Knowledge-Essential-Intermedia...) will give you a quick run of the gotchas you're to avoid. From there, move to Scott Meyer's books, which will give you some good foundational knowledge on how features of the language work together. In particular I like that each concept is presented in a bite-sized chapter that you can read in a couple of hours and think about for the rest of the day. Even though the first two are about "classic C++" I wouldn't skip them. For a glimpse of the true power of modern C++, check the Boost Hana library docs, hopefully this will serve you as motivation to keep on going. Above all, don't do this alone. The compiler errors that you get once you start applying modern (template) techniques can be a bit of a rabbit hole and takes a bit to get an eye for deciphering them. Lean on coworkers, local user groups and/or the C++ slack group which is pretty supportive. Best of luck.

Load more comments