- We rely on clang-format-4.0 for code format.
- Make sure to format your code before you commit, since we have not set up a githook for it.
- Variable names should consist of lowercase words connected by underscores, e.g.
density_field
. - Class and struct names should consist of words with first letters captalized, e.g.
MultigridPreconditioner
. - Template classes should start with T, like
TVector, TMatrix, TArray
; - Reserve the name without
T
for specialized classes, e.g.using Vector=TVector<real, dim>
.
- Reserve the name without
- Template classes should start with T, like
- Macros should be capital start with
TC
, such asTC_INFO
,TC_IMPLEMENTATION
. - We do not encourage the use of macro, though there are cases where macros are inevitable.
- Macros should be capital start with
- Filenames should constist of lowercase words connected by underscores, e.g.
parallel_reduction.cpp
.
- Put in the projects folder
- We allow the use of old-style C casting e.g.
auto t = (int)x;
- Reason:
static_cast<type>(variable)
is too verbose.
- Reason:
- We allow the use of old-style C casting e.g.
- Think twice when you use
reinterpret_cast
,const_cast
. - Discussions on this in Google C++ Style Guide.
- Be considerate to your users (this includes yourself in the near future).
- Use
auto
for local variables when appropriate. - Mark
override
andconst
when necessary.
- C language legacies:
printf
(usefmtlib
instead).new
&free
. Use smart pointers (std::unique_ptr, std::shared_ptr
instead for ownership management).- Unnecessary dependencies.
- Prefix member functions with
m_
or_
. Modern IDE can highlight members variables for you. - Virtual function call in constructors/destructors.
- C++ exceptions
NULL
, usenullptr
instead.using namespace std;
in headers global scope.typedef
. Useusing
instead.
- To build the documentation:
ti doc
orcd docs && sphinx-build -b html . build
.