Naming and layout suggestions
NL.17
Use K&R-derived layout
Reason
This is the original C and C++ layout. It preserves vertical space well. It distinguishes different language constructs (such as functions and classes) well.
Note
In the context of C++, this style is often called "Stroustrup".
This is a recommendation for when you have no constraints or better ideas. This rule was added after many requests for guidance.
Example
struct Cable {
int x;
// ...
};
double foo(int x)
{
if (0 < x) {
// ...
}
switch (x) {
case 0:
// ...
break;
case amazing:
// ...
break;
default:
// ...
break;
}
if (0 < x)
++x;
if (x < 0)
something();
else
something_else();
return some_value;
}
Note the space between if and (
Note
Use separate lines for each statement, the branches of an if, and the body of a for.
Note
The { for a class and a struct is not on a separate line, but the { for a function is.
Note
Capitalize the names of your user-defined types to distinguish them from standards-library types.
Note
Do not capitalize function names.
Enforcement
If you want enforcement, use an IDE to reformat.