Code style guide

Jean-Michaël Celerier edited this page Sep 5, 2018 · 3 revisions



  • Use modern C++ features where it makes sense and makes the code cleaner.
  • Try to use value semantics and pass-by-reference most of the time.
  • Try to limit the use of pointers, when it is necessary use std::unique_ptr unless a problem specifically calls for std::shared_ptr.
  • Try to limit inheritance, and especially the use of virtual functions.
  • If a virtual function makes sense, don't forget to :
    • Make the destructor virtual.
    • Put the destructor implementation in a .cpp file.
  • Use variant for closed polymorphism (when you know all the types from the beginning).
  • Use string_view when a function works on strings without storing them, and use std::string for storing.
  • Use optional when parsing something or when a function may not always yield a result.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.