From Mageia wiki
Contents
Indentation
- No tabs
- 4 Spaces instead of one tab
Variable declaration
- Each variable declaration on a new line
- Each new word in a variable name starts with a capital letter (so-called camelCase)
- Avoid abbreviations
- Take useful names. No short names, except:
- Single character variable names can denote counters and temporary variables whose purpose is obvious
- Variables and functions start with a lowercase letter
Example:
// wrong int foo; long bar, foobar; // correct int foo; long bar; long foobar;
Whitespace
- Use blank lines to group statements
- Use only one empty line
- Use one space after each keyword
- For pointers or references, use a single space before '*' or '&', but not after
- No space after a cast
Example:
// wrong
int* foo;
if(true){
}
// correct
int *foo;
if (true) {
}
Braces
As a base rule, the left curly brace goes on the same line as the start of the statement.
Example:
// wrong
if (true)
{
}
// correct
if (true) {
}
Exception: Function implementations, class, struct and namespace declarations always have the opening brace on the start of a line.
Example:
void debug(int i)
{
log("foo: %i", i);
}
class Debug
{
};
Use curly braces even when the body of a conditional statement contains only one line.
Example:
// wrong
if (true)
return true;
for (int i = 0; i < 10; ++i)
log("%i", i);
// correct
if (true) {
return true;
}
for (int i = 0; i < 10; ++i) {
log("%i", i);
}
Switch statements
Case labels are on the same column as the switch
Example:
switch (myEnum) {
case Value1:
doSomething();
break;
case Value2:
doSomethingElse();
// fall through
default:
defaultHandling();
break;
}
Line breaks
Try to keep lines shorter than 100 characters, inserting line breaks as necessary.
Source: Coding Style