← Back to team overview

cuneiform team mailing list archive

Re: Code style discussion

 

To set a code style is a good idea.

- indent 4 spaces, NO tabs

Good rule.

- beginning brace is always on the same line as
> if/else/for/while/function definition/etc
>
I prefer beginning brace on next line like
    if...
    {
        // if body
    }
and AFIK this style is more convinient. If you use an editor (such as vi)
that supports brace matching you can move to the opening brace hit a key and
the editor finds the matching closing brace.
But this question is not a religious issue for me.


> - no space between if/while/etc and parenthesis, one space after
> comma/semicolon, like this:
>
> for(i=0; i<value; i++)
>
I prefere insert single space after keyword (if/while, preprocessor, etc.)
and not insert a space betwen function name and open brace '('.
As a rules it can be like this:
- Put a whitespace next to keyword. Do put round bracket next to function
names without whitespace.
- Semicolons in for statments should be followed by a space character.
- Commas should be followed by a whitespace.
    func(par1, par2, par3);
  is better, then
    func(par1,par2,par3) ;

As for white spaces I can suggest:
- Binary (conventional) operators should be surrounded by a space character.

    sum = a + b * c;
  is better, then
    sum=a+b*c;
- Remove trailing white spaces.

Follow ups

References