-
-
Notifications
You must be signed in to change notification settings - Fork 34
Code style guide
Jean-Michaël Celerier edited this page Sep 5, 2018
·
3 revisions
-
Indentation : 2 spaces.
-
Classes & structs naming :
lower_case_with_underscores
. -
Files naming :
like_this.hpp
,like_that.cpp
. -
Public member naming :
lowerCase
. -
Private member naming :
m_lowerCase
. -
A Qt Creator code style XML file is available in the repository
- 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 forstd::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 usestd::string
for storing. - Use
optional
when parsing something or when a function may not always yield a result.