For function and class definitions, it is unambiguous if you put the opening brace on the next line:


void some_function(int param)
{
        //function body
}

class SomeClass
{
        //class body
};


But for ifs, fors, whiles etc..., there are several possibilities for the braces and parenthesis:

if(some_condition)
{
        //...
}

if( some_condition )
{
        //...
}

if ( some_condition )
{
        //...
}

if (some_condition)
{
        //...
}

if (some_condition) {
        //...
}

The preferred way, which is the last, and proposed by K&R, is to put the opening brace last on the line, and put the closing brace first. The reason is to minimize the number of empty lines.

The spaces in math expressions should follow this style:


float a, b, c, d;
int e, f, g, h;

a = (b + d) / (c * d);

e = f - ((g & h) >> 10);    //good
e =f-( (g&h ) >>10);        //bad
Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates