On Tue, Dec 9, 2008 at 3:18 PM, nathan binkert <[EMAIL PROTECTED]> wrote:
> Ok, we've talked a lot about style, but the document hasn't really been 
> updated:
>
> Things to add:
>
> 1) if/while/for statements must use braces unless the entirety of the
> statement fits in two lines.  if/elseif/else blocks can skip the
> braces only if all blocks fit on two lines.  i.e. (if: 2 lines,
> if/else: 4 lines, if/elseif/else: 6lines)

I'd word this a little differently (assuming this is what you're trying to say):
1. Braces are optional if the body of the block fits on one line.
2. For if/else constructs (including extended if/else if/else chains),
all the bodies of all the blocks must fit on one line (each) for any
of the blocks to omit braces.

That said, this whole rule seems a little overkill to me.  Clearly if
you have more than one statement you need braces anyway, so all #1
really says is that our style also requires braces if you have a
single-statement body that takes more than one line... but do we
really care about that?  (Historically #1 is also significant in that
we used to have a rule that you always had to have braces even if the
body was a single statement, but I don't think we need an explicit
rule to repeal that, especially since the original rule never made it
to the wiki page to begin with.)

And #2 just seems terribly nit-picky... seems to me either you can
elide the braces when you have a single-statement body or not, and I
don't want to go add braces to all N branches of an if/else chain just
because one of the else-if blocks went from one statement to two.  In
fact that was the main reason for requiring braces all the time
anyway: so you don't have to go adding or deleting braces

Also if we do keep a rule like this we should make sure that we
clarify "optional" to make it clear that if there are braces around a
single-line body that's not a violation of the style.

>
> 3) Functions:
> template statements should be on a line by themselves
> return types should be on their own line
> function names should be at the beginning of the line (subject to
> indenting rules).
> EXCEPTION: In class bodies, the entire statement can be on one line if
> it fits within the column limit.
>
> Bad:
> class Foo
> {
>  int foo() const
>  {
>     do something;
>     return var;
>  }
> };
>
> Good:
> class Foo
> {
>  int
>  foo() const
>  {
>     do something;
>     return var;
>  }
> };
>

Part of this (except for the bit about templates and the exception for
inline functions in class bodies) is already there.

Steve
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to