Indentation for if's:
Code:
if (conditional)
{
DoSomething();
if (another_conditional)
{
DoSomethingElse();
}
}
You don't have to provide braces if the conditional only leads to one statement but I find that always using braces for if's results in much cleaner code.
If you are using MSVC you can usually rely on their default indentation to be correct. There are only two areas that really annoy me in MSVC:
- It does not indent over once before writing the body of a class.
- It indents braces inside switch statements.
IE: MSVC's suggestion
Code:
class Example
{
public:
Example();
...
};
switch (some_value)
{
case 0:
{
DoSomething();
break;
}
}
My preference:
Code:
class Example
{
public:
Example();
...
};
switch (some_value)
{
case 0:
{
DoSomething();
break;
}
}
Other than those two areas I usually just allow the compiler to figure out the indentation. Of course it has become so automatic for me I'm not sure what the editor in the compiler actually suggests anymore.