Hacker News new | ask | show | jobs
Ask HN: Ressources to update old C++ skills
8 points by HerrmannM 2348 days ago
Hi All!

I used to do some C++ 10 years ago. I now have to work on some new projects that will require C++. I know that C++ evolved a lot. Without being after all the new features, I'm looking to write safer code (eg through safer pointer handling).

Do you know about some ressources focusing on how to code in C++ in a "modern" and safe way for people with previous experience in the language? For example, after some search, I have "Effective Modern C++" in mind (focusing on c++11/14), but I would love to hear what the HN community has to say before jumping in!

Note: As much as I appreciate other safer languages, C++ is a requirement so I'm really looking for safety in C++.

Thanks!

2 comments

'A tour of C++' by Stroustrup is a good overview of modern C++.

I recently got back into C++ after big hiatus, just like you, and for me the things that changed are:

  - definitely the things you mentioned: much safer constructs (unique_ptr, move semantics)
  - the use of CMake as a build system
  - much less focus on arcane templates and libraries like Boost
  - new tools like sanitizers
  - new IDEs (CLion)
Thanks for sharing! I'll be sure to check that book.

Even if CMake is basically a defacto standard, I have a CMake trauma... Do you have experience with things like Scons/Ninja?

For the sanitizers, I had a look at the one from google: https://github.com/google/sanitizers Did you work with any of those, or was it something else?

I definitely have my eyes on CLion, I'll have to convince my University to get a licence as they are already bulk paying for MS Visual Studio (but that one does not work on linux...)

CMake is the defacto standard for a reason. It's a great tool. However, it definitely has a steep learning curve. It took me many hours to get it, because the documentation is, I would not say 'bad' (it's actually really good) but it's really a reference more than a tutorial. So you'll have to hunt for good tutorials on the web, and just like C++ there is an old way to write CMake and a modern way :) I can't recommend a particular tutorial but make sure they talk about 'modern CMake'.

I used SCons a long time ago. It worked but it was extremely slow. Ninja is not designed to be written by hand, it's a back-end to be used by CMake, etc.

Yes, sanitizers are now included in GCC and Clang (it's the same code base, initially developed by Google). Support varies by platform but on Linux/amd64 all of them are available. UBSan, LSan are easy to use and have little impact on performance. ASan and TSan are more expensive but they work well; not unlike Valgrind but still faster. MSan is a pain to configure because all the code must be instrumented (that includes dynamic libraries you use). Not that easy in practice.

All right, thank you for the feedback!
In the end, I went for

- Principles and Practice Using C++ by Stroustrup, covering C++11:14

- C++17 - The Complete Guide by Nicolai M. Josuttis

- using CLion

If you already know C++03, I'd first take a look at the C++11 Wikipedia page. (It might be less bloated if you go back in the page history, so try going back to 2012.) I don't think guides or resources beyond that are really necessary to grasp what's new and how to make use of it, except for precise reference documentation.
Going back in time; good tip!

I don't fully trust my actual knowledge of C++03, I always fear to get bitten by all the implicit things happening in the background (like how the compiler will defined the default constructors -- at least I know I might get bitten, so I'll be on the cautious side). For that reason, the book my be preferable in my case...