-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Context
@PabRod requested some advice on C++ projects via Teams. The advice he received was valuable enough to register it here and, perhaps, incorporate it to the guide.
Thanks @egpbos for suggesting it.
Original message
C++ for RSEs
By @PabRod
Dear colleagues, I invoke your collective wisdom:
I am refreshing my C++ skills (didn't touch it since 2015), and I'm finding it hard to find a book/tutorial with the appropriate level and scope.
Most of the materials I've found are either too basic (I'd rather not read a full chapter about what a for loop is), way too long, or out of tune with research software engineering.
I am particularly interested in how to implement best practices (testing, documenting, ...), and there seems to be a constellation of frameworks. Any advice?
Answers
@c-martinez
https://youtu.be/H9lWRVma2EE?si=3ayYggQ34qMNCCxC
@LourensVeen
I use doxygen for documentation, together with the breathe plugin for Sphinx so that I can combine Python and C++ API docs (and the rest using rst) into a single documentation site. For testing, GoogleTest or Catch2, although those have kept getting heavier and doctest looks interesting. Mocking in C++ isn't easy, there's GoogleMock to accompany GoogleTest, but you effectively have to write Java in C++ to be able to use it, you can't e.g. mock a function with it. I have my own creative solution using the preprocessor for that, which is a hack and it has some drawbacks, but it works and it's readable.
For research software engineering, you can just write bad code, it's the standard. Are there any particular applications or fields you're interested in though?
@PabRod
Thanks for your answers!
So far, no particular fields. I just have a personal toy project I like to translate to different languages as an exercise
@LourensVeen
Is it data processing, machine learning, calculations, simulation, rendering, infrastructure, ...?
Also, you're already familiar with modern C++, things like smart pointers and const correctness and lambdas and such?
@PabRod
I'm getting used to modern C++ only recently 🙃
As I said, didn't touch it since 10 years ago.
@LourensVeen
Yeah, that makes sense. The first bits came out with C++11, but it takes some years to get the compiler support and for people to start using it. (I'm currently considering moving from C++14 to C++17 for MUSCLE3, because it looks like even old machines now have new enough compilers that I can do that. It's a 7 year old standard by now...)
Modern C++ is almost a new language and learning it will teach you a lot about how to do things right, so I'd definitely start with that. Stroustrup's book is the standard reference, and Scott Meyers' Effective Modern C++ is also often recommended. Searching for "modern C++" online will give you a lot of stuff to look at as well.
@suvayu
For testing I quite like Catch2 (Lourens mentioned above),
for handling data, particularly if you are going to use it from another language or process, or (de)serialisation checkout https://arrow.apache.org/ .
As for RSE specific things, my feeling is a lot of the projects end up being "port to the GPU" or "make use of HPC", so that might be worthwhile to look at. Last week we had a "GPU programming with directives" talk by Leon at the HPC SIG (can't recall if you were there).
I would say getting familiar with build systems is also crucial, CMake is the de-facto beast - can't live with it, can't live without it. I have another pet peeve, but haven't seen many people talk about it, it's to make your project's build system compatible with "package managers" like vcpkg and conan. I played around a bit with vcpkg, diving a bit deeper and covering conan are on my TODOs. If you are interested, we could do it together.
Some high quality podcasts:
- https://adspthepodcast.com/ : chaotic and fun, but when it goes deep, it gets really serious
- https://cppcast.com/ : longest running C++ podcast
- https://www.twoscomplement.org/ : casual, mixture of high quality software engineering, and low-level C++ stuff, one of the hosts is the original author of the compiler explorer
- https://www.youtube.com/@cppweekly : very good, practical, modern C++ short videos, original host of the CPP Cast
There are also some domain specific stuff, e.g. LLMs and language bindings, but maybe I'm jumping ahead too much (feel free to bother me, can't say I'll have answers, but I'll definitely join your quest with excitement )