Whitespace

  • Indent using two spaces.
  • Indent line continuations at least four spaces.
  • Don't use tabs.
  • Use a space after keywords: if, while, for, switch.
  • Use a space after delimiters: comma, semicolon, colon.
  • Don't use spaces around unary operators, including ., ->, [].
  • For pointers/references, the */& should immediately follow the type.
  • Don't use "extra" whitespace after function names, parentheses, brackets.

Formatting

  • Limit line lengths to 80 characters.
  • Use Bjarne's coding style for braces.
  • Don't put braces around single-statement blocks.
  • Use parentheses around bit-wise logical operators.

Comments

  • Use only significant comments.
  • Use doxygen comments for public interfaces.
  • Put design comments in a design document.

Functions

  • Names should be verbs.
  • Pass lightweight parameters by value.
  • Use a pointer (instead of a reference) for a parameter that returns a value.
  • Avoid returning values in a parameters.
  • It's fine to return early.

Standard C++

  • Use modern language features.
  • Use nullptr.
  • Use explicit for single-argument constructors.
  • Use class for template parameters instead of typename.
  • Avoid using the C preprocessor.

Standard Library

  • Use std::array instead of C++ arrays.
  • Use std::vector instead of arrays.
  • Prefer std::vector container.
  • Use smart-pointers to manage resources.

rci Library

  • Use rci::InternallyLocked instead of std::mutex.
  • Use rci::numeric_cast instead of static_cast.
  • Use rci::pointer_cast instead of static_cast.

Errors

  • Handle unexpected errors with exceptions.
  • Use <system_error> or <stdexcept>.
  • Use RCI_ENFORCE(), RCI_ASSERT(), and RCI_VERIFY().
  • Throw exceptions for unexpected errors.
  • Don't throw exceptions for expected errors.

Names

  • Use namespaces.
  • Use camelcase.
  • Only use all uppercase for preprocessor macros and constants.
  • Capitalize names of namespaces, types, globals, and static members.
  • Prefix an underscore to private member variables (or m).
  • Postfix an underscore to member function parameters.