doc(style): update C++ style guide
This commit is contained in:
parent
1452e9319e
commit
4a66712ef2
1 changed files with 45 additions and 14 deletions
59
doc/style.md
59
doc/style.md
|
@ -157,30 +157,61 @@ Similarly, we write `x < y + 1` instead of `x<y+1`.
|
|||
Google's C++ Style Guide
|
||||
------------------------
|
||||
|
||||
We are using a modified version of
|
||||
[Google's C++ Style Guide][google-style]. Here is a list of checks
|
||||
that we *disabled*:
|
||||
We are using a modified version of [Google's C++ Style Guide][google-style].
|
||||
We also have our version of Google's style checker [cpplint.py][cpplint].
|
||||
You can run the checker over the codebase by typing:
|
||||
|
||||
- Namespace should be terminated with "namespace" [readability/namespace]
|
||||
make style
|
||||
|
||||
If you use Ninja, you can check by ``ninja style``. It is also a part of testcases and can be run by
|
||||
|
||||
ctest -R style_check
|
||||
|
||||
*Disabled* Features:
|
||||
|
||||
- Namespace should be terminated with "namespace"
|
||||
- At least two spaces is best between code and comments
|
||||
- Do not use ``dynamic_cast<>``. If you need to cast within a class
|
||||
hierarchy, use ``static_cast<>`` to upcast. Google doesn't support
|
||||
RTTI.
|
||||
- "public:" should be preceded by a blank line [whitespace/blank_line]
|
||||
- Missing space before ``{`` [whitespace/braces]
|
||||
- "public:" should be preceded by a blank line
|
||||
- Missing space before ``{``
|
||||
- Found C system header after C++ system header. Should be:
|
||||
environment.h, c system, c++ system, other. [build/include_order]
|
||||
[4]
|
||||
environment.h, c system, c++ system, other.
|
||||
- Labels should always be indented at least one space. If this is
|
||||
a member-initializer list in a constructor or the base class list in
|
||||
a class definition, the colon should be on the following line.
|
||||
[whitespace/labels]
|
||||
- You don't need a ``;`` after a ``}`` [readability/braces]
|
||||
- You don't need a ``;`` after a ``}``
|
||||
- No ``#ifndef`` header guard found
|
||||
- Streams are highly discouraged.
|
||||
- Extra space before ``(`` in function call [whitespace/parens]
|
||||
- Else clause should never be on same line as else [whitespace/newline]
|
||||
- Extra space before ``)`` [whitespace/parens]
|
||||
- Is this a non-const reference? If so, make const or use a pointer. [runtime/references]
|
||||
- Extra space before ``(`` in function call
|
||||
- Else clause should never be on same line as else
|
||||
- Extra space before ``)``
|
||||
- Is this a non-const reference? If so, make const or use a pointer.
|
||||
- All parameters should be named in a function
|
||||
|
||||
Modified Features:
|
||||
|
||||
- Add ``#include <list>`` for ``list<>``
|
||||
|
||||
=> *Check* ``std::list`` instead of ``list`` because we do have our own ``lean::list`` type.
|
||||
|
||||
- Add ``#include <algorithm>`` for copy
|
||||
|
||||
=> *Check* ``std::copy`` instead of ``copy`` because we do have our own ``lean::copy`` method.
|
||||
|
||||
- Do not use namespace using-directives. Use using-declarations instead.
|
||||
|
||||
=> *Allow* this if filename contains "tests/"
|
||||
|
||||
- Small and focused functions are preferred: foo()
|
||||
has xxx non-comment lines (error triggered by exceeding 500 lines).
|
||||
|
||||
=> *Allow* this if filename contains "tests/"
|
||||
|
||||
- Include the directory when naming .h files
|
||||
|
||||
=> *Allow* this if the included filename is "version.h" which is generated by cmake.
|
||||
|
||||
[google-style]: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
|
||||
[cpplint]: /src/cmake/Modules/cpplint.py
|
||||
|
|
Loading…
Reference in a new issue