|
rippled
|
Coding standards used here gradually evolve and propagate through code reviews. Some aspects are enforced more strictly than others.
These rules only apply to our own code. We can't enforce any sort of style on the external repositories and libraries we include. The best guideline is to maintain the standards that are used in those libraries.
new or delete.If you want to do something contrary to these guidelines, understand why you're doing it. Think, use common sense, and consider that this your changes will probably need to be maintained long after you've moved on to other projects.
The goal of source code formatting should always be to make things as easy to read as possible. White space is used to guide the eye so that details are not overlooked. Blank lines are used to separate code into "paragraphs."
operator=).! operator should be preceded by a space, but not followed by one.~ operator should be preceded by a space, but not followed by one.++ and -- operators should have no spaces between the operator and the operand.foobar (1, 2, 3);if statement.}.if statements all-on-one-line. The exception to this is when you've got a sequence of similar if statements, and are aligning them all vertically to highlight their similarities.if-else statement, if you surround one half of the statement with braces, you also need to put braces around the other half, to match.SomeObject* myObject. Technically, a more correct spacing would be SomeObject *myObject, but it makes more sense for the asterisk to be grouped with the type name, since being a pointer is part of the type, not the variable name. The only time that this can lead to any problems is when you're declaring multiple pointers of the same type in the same statement - which leads on to the next rule:SomeObject* p1, *p2; - instead, always split them out onto separate lines and write the type name again, to make it quite clear what's going on, and avoid the danger of missing out any vital asterisks.& next to the type rather than the variable, e.g. void foo (Thing const& thing). And don't put a space on both sides of the * or & - always put a space after it, but never before it.const should be placed to the right of the thing that it modifies, for consistency. For example int const refers to an int which is const. int const* is a pointer to an int which is const. int *const is a const pointer to an int.
1.8.17