These are guidelines, not laws. You are free to deviate, but make sure you have a good argument for doing so.
Guidelines that could be easily automated, have been. Please install:
-
EditorConfig plugin, so your editor can apply some of the formatting right as you type;
-
clang-format
(part ofclang
package in most Linux distributions); -
our pre-commit hook, which runs
clang-format
on each commit you make. Just run:$ ln -s ../../git-hooks/pre-commit .git/hooks/pre-commit
Note:
../..
is not a mistake.
Always leave the campground cleaner than you found it. In other words, if you work on some part of the system and find some code that violates these guidelines without a reason, make a separate commit that cleans up that code.
Rationale: it's impossible to automatically upgrade the whole codebase to follow these guidelines, but doing it bit by bit is very feasible.
Put your #include
statements in the following order:
- related header, in double quotes (e.g. "foo.h" for "foo.cpp");
- a blank line;
- headers from outside the repository, in angle brackets (e.g.
<cassert>
or<string>
); - a blank line;
- headers from inside the repository, in double quotes.
Rationale:
- putting related header in a prominent place makes it easier to navigate the code;
- visually distinguishing between outside and inside headers makes it easier to understand the dependencies and navigate the code.