Skip to content
Daniel Zahka edited this page Sep 1, 2022 · 1 revision

Style Guide

C++

Rules:

  • auto always
  • East const e.g. (auto const val = ..., auto const& ref = ...)
  • For naming, I use: the google c++ style. Ignore the file naming rules, I use .cpp/.hpp extensions.
  • Separate private interfaces from public interfaces.
    • Put library public interface header files .hpp in a<library_src_dir>/include subdirectory. #include these headers with angle brackets #include <>
    • Put library private interface headers next to the .cpp files, and include them with quotes #include ""
  • Don't create a new feature without tests
  • You can only test the public interface of a library. If you find yourself wanting to test something that is not part of the public interface, you probably need to split the component into another library that has the feature in its public interface.
  • Don't use output parameters in functions. If you want to return multiple things from a function, use c++ destructuring e.g. auto [val1, val2] = MultiReturnFunc();
  • Put whatever possible in .cpp files. Only put things in .hpp files if the client needs the implementation along with interface e.g. templates, constexpr functions
  • Don't copy and paste. Refactor if you have to.
  • Don't #include <iostream> or use std::cout for logging. Use spdlog for logging and fmt for formatting strings.
  • If you want to make a note to implement or fix something create a github issue, don't leave inline comments //TODO:. If you find TODO comments that I put in there you can make an issue and delete them if you want.

cmake

Control the visibility of dependencies using PRIVATE, INTERFACE, and PUBLIC specifiers.

clang-format

Set up your editor to use clang-format.

git

  • Don't commit broken code
  • Don't commit code that doesn't pass tests
  • try to break up commits into single features

Clone this wiki locally