Hacker News new | ask | show | jobs
Ask HN: I whant to Learn C++ not Rust!!
25 points by sptth 1510 days ago
I would like to learn C++ and I am looking for good learning resources (books, courses, tutorials, docs...). I would also like some introduction to modern libraries, compilers, latest standards, good practices...yes I know I want to learn everything. Well I am just asking here for good places to start my journey, also any advice other than "learn Rust"? I don't want to learn Rust (not for now at least)

Thanks in advance! ;)

17 comments

It won't help you learn C++ from scratch, but once you know a bit about it, the Abseil tips published by Google are a remarkably useful resource to learn best practices and modern C++: https://abseil.io/tips/

They are one of the main tools used internally at Google to ensure engineers who have to use C++ stay on top of language evolution and avoid common pitfalls.

Quite good though it looks a bit orphaned. Saved for the future thanks ;)
Most importantly, code something in c++! Being "book-smart" with nothing to show for it is pretty much useless. A simple Snake or Tetris clone in SDL is a super rewarding first project, or you could give Advent of Code a go as it lets you solve a lot of cool puzzles that fit in a couple of hours at worst. As for books, I can recommend Effective Modern C++ by Scott Meyers. CppCast is a great podcast that can get you up to speed on the C++ ecosystem.
This is great advice!
CppCon, one of the major C++ conferences, has started some years ago a series of presentations, called "Back to basics", that are aimed at people that are just starting out with the language. Each presentation is thematic and can be watched independently from the others. The presentations can be found on the CppCon youtube channel:

- CppCon 2021, https://www.youtube.com/playlist?list=PLHTh1InhhwT4TJaHBVWzv...

- CppCon 2020, https://www.youtube.com/playlist?list=PLHTh1InhhwT5o3GwbFYy3...

- CppCon 2019, https://www.youtube.com/playlist?list=PLHTh1InhhwT4CTnVjJqnA...

nice!
Can someone share how modern C/C++ build systems work?

Part of the reason I’ve gravitated towards Rust as my system’s language is because every time I look at a large C++ project there are CMake / Automake / Make definitions that are really hard for me to read and understand. Some of them even seem to use symbols I can’t find in these tools’ manuals.

Learning to use CMake/autotools is kind of like learning SQL when all you know is Python.

CMake/autotools syntax is nothing like C/C++, or actually any general purpose programming language, so you basically need to become familiar with this new language/paradigm in addition to knowing C/C++.

But like with most programming languages, once you grok it you will more easily learn other build systems. They all solve similar problems after all.

You just gotta pick one and learn it. I mean, you don't have to, you can write your own build scripts in bash or whatever but eventually you'll just end up inventing a new, probably crappy build system :)

> really hard for me to read and understand.

I agree and empathize. I tried figuring them out by looking at other people's Makefiles but they are all so wildly different between projects, it's like there is no standard/convention to writing them (and there is not as far as I can tell). Additionally, make has so much magic/internal/inferred/assumed behavior, variables etc. that it's really hard to figure out what they do by just reading them. Especially since they don't use familiar flow control structures like functions calls or even gotos. This also makes debugging hard.

I only learned make when I've started writing my own C/C++ projects. The documentation is actually quite good. Going from make to CMake was much easier then.

Herr are some great resources:

https://en.cppreference.com/w/

https://www.learncpp.com/

https://hackingcpp.com/

Books:

A tour of C++ 2nd Ed by Bjorne Stroustrup covers C++17 and a new version is in the works to cover C++20 and maybe 23.

https://nostarch.com/cppcrashcourse

https://hackingcpp.com/ looks promising.
I've been programming in C++ for the past 15+ years, from some toy UI applications to things like a fully-featured software DSP for a telecom gateway.

I don't want to discourage you, and I think everything I did during this time was a good experience and taught me a lot. If you feel that's important for you, go ahead.

My point of view, which comes from my personal experience: even though Rust has some limitations, a number of areas for further development and a few rough edges for lower-level development, at this point in my career I don't want to touch C++ anymore unless I have no other choice.

Modern C++ is much better but it is not a paradigm shift (safe by default), the same way "labelled goto" (ie, C) is better than "numbered goto" (ie, BASIC) but it is still not a while/for.

You might reach a similar conclusion, or you might not. I just want to leave this here for you to reflect upon.

Regarding material, it all depends on the platform and what you would want to use C++ for. There are many references here already, so my advice goes to focus on C++ concepts and techniques and not too much on specific libraries - since they can be unavailable or impractical for certain environments/platforms.

> at this point in my career I don't want to touch C++ anymore unless I have no other choice.

What would you use now?

I am working my way through this https://www.freecodecamp.org/news/learn-c-with-free-31-hour-... and I enjoy it

It goes pretty fast if you've programmed before but covers a decent amount of the newer stuff. Once you get the fundamentals down you can probably figure out the C++20 features through the docs

Thanks for the help, will definitely have a look!
I'm not a C++ dev, but I would recommend JetBrain's CLion IDE for C/C++ development. It has great integration with build tools, debugger, valgrind, iperf(for profiling). It's a bit pricy, but it's possible to redo the free trial indefinitely.
I am more of a CLI user I've been using neovim with coc for js, ts, python and even solidity development. I will try first to have things working in my usual dev environment, but thanks for the suggestion I've heard good things about CLion and could probably get a free licence.
For vim, many of my coworkers love YouCompleteMe, which provides IDE-like autocompletion and more. I don't use autocompletion much even in an IDE, so I mostly stick with ctags in vim to let me jump to definition of functions/variables/classes, etc.
They used to have free licenses for students, too. Not sure if that's available or useful for OP.
Which C++ do you want to learn? There’s a lot of history there. I’d look at various C++ libraries over the years written in the different dialects. C++ has so many variants it’s really hard to say it’s a single language as each one reads so differently. It’s like saying English is a single language without understanding there are wildly different dialects and meanings to the same thing.
I guess I will deal with that once I start 'mastering' the basics, for the moment anything good that covers C++17 suits me.
All of the resources I used to learn C++ are probably obsolete at this point, so I can't give any advice on how to get started, but I highly recommend reading Effective Modern C++ after you learn the basics, which covers a lot of best practices.
Effective Modern C++ was mentioned here and also is one of the best rated books out there, must buy it.

Thanks ;)

If you don’t know already, learn how to use a debugger. Also valgrind is very helpful. And if it hasn’t changed in the last years, Clang usually provides more user friendly error messages compared to GCC.
AddressSanitizer aka libasan is also wonderful for tracking memory errors. I find it both faster than valgrind and it has fewer false positives. I still use valgrind for 3rd party code, but prefer libasan for first party code, and insist on a clean run of the unit test suite using a libasan build before merging.
Piggybacking on this: Is there any book out there which covers C++ 20? Most of the reference books suggested on forums (SO, IRC/Discord channels) seem to cover C++ 17 or 14, or even worse, 11.
Afaik major changes where introduced in C++11 and later on in C++17. I would be happy finding anything that covers up to the C++17 standard.
I've been enjoying a series of youtube tutorials by someone called 'TheCherno' on my own C++ journey (although I'm still at the very beginning of it!).
I looked him up. Not bad. One content that I recommend to peers that are after C++ is this one particular course from Wondrium. https://www.wondrium.com/introduction-to-c-programming-conce... Also the CS50 for the very basics to the programming.
I would start with "A Tour of C++", by Stroustrup.
Hi thanks for the recomendation, looks pretty good and complete!

Is there any edition that includes modern standards? (c++17 minimum)

Um... from memory, the edition I have covers c++14. I don't know if there's a more recent edition.
The second edition covers C++ 17.
It does!
flagged? rustaceans are a little rusty today
There is no easy way. You must work through https://en.cppreference.com/w/
This is such bad advice that I think it's a joke. You don't read the reference to learn a language.
My guess is it’s a quasi-joke, but it’s not uncommon a suggestion with say C.

In this case though, I can count how many jokes about “I’ve been writing C++ for 10 years when do I finally learn it”.

f****!

:')