-
Notifications
You must be signed in to change notification settings - Fork 0
7. CPP Workflow
We highly recommend that developers write code using c++11, or newer, ideally c++14 or newer. For full disclosure, we note that, as of early 2023, c++20 is the latest stable release of the language (as c++23 is still in feature-freeze), and that the styleguide we provided and follow is technically geared towards c++17, which is the most used version of the language, currently. However, c++11 was a major overhaul from previous versions, and it is still found in many softwares across industry and academia. Thus, for most intents and purposes c++11 is a perfectly adequate choice for writing C++ code, with, unfortunately, the major exception of unit testing within most modern well-established frameworks, as we will see shortly. Thankfully, some alternatives are still available.
To enhance reproducibility, we require all C++ code to be packaged. While the build system adopted to package your C++ code may vary within your organization/research group, (and there is no single method to rule them all, as detailed here) there are a few common good practices that all of those methods follow. E.g., having a src/ directory as your main compilable source location, a build/ directory where ephemera build results will lie, etc. For instance, a good set of habits for packaging your C++ code is the Pitchfork Layout. If we had to make one recommendation re: build systems, given its integrability with well-established unit testing frameworks (particularly GoogleTest, more on that later), and simplicity of use, CMake would be a natural candidate, if you were starting a project from scratch.
Many languages have a dominant testing framework widely accepted and used by most developers. Unfortunately, the picture for C++ is a little more blurry in this regard. While we will ultimately accept all unit testing, we would like to give a few recommendations re: established testing frameworks:
If you plan on using c++14 or newer:
-
GoogleTest: a very popular choice (possibly the most popular nowadays), especially within the industry, as it is probably the most complete testing framework available as open source, going way beyond unit testing. It comes with ample documentation and a very helpful user's guide. If you are already familiar with generic unit testing frameworks, we recommend you opt for this choice.
-
Catch2: less comprehensive than GoogleTest in terms of the kind of tests it allows to run, but its header-only nature makes it a more natural choice to get started with for unit testing. Light, quick and easy to use.
NOTE: Both of the aforementioned frameworks require c++14 or newer, and they thus do not support c++11 semantics.
If you plan on using c++11:
- Boost.Test: somewhere in between GoogleTest and Catch2, but with the major advantage of still supporting c++11
Whatever your choice, make sure to design adequate unit tests as part of the package, so that the reviewer can better evaluate your PR, by mainly focusing on the code’s logic and readability.