C++ Best Practices
Opinionated C++ one page best practices guide. Adapt according to your project’s requirements.
- Use the Pitchfork project layout conventions.
- Build your code using CMake.
- Never manually format code, use clang-format to format your code.
- Write unit tests using Catch.
- Build your tests with STL in debug mode:
- Build and run your tests with sanitizers enabled.
- Use a fuzzer to test handling of untrusted input (afl, libFuzzer, honggfuzz).
- Enable at least
-Wall -Wextra -Wpedantic
warning options (GCC, clang). - Use static analysis (clang-tidy, cppcheck, coverity, PVS-Studio).
- Use compiler options to harden your application from security exploits:
- Consider enforcing a coding convention:
More in depth guide by Jason Turner.