The great parenthesis debate

Appetizer:

The coding standard where I work dictates that the return type should be on a separate line to the rest of the function header, for example:

void
Foo::doStuff()

and not

void Foo::doStuff()

I have yet to discover why this is, but I quite like it. However, the situation with the brackets is rather different.

Main Course:

The standard says:

if ( true ) {
// Do stuff.
}
else {
}

Which I can live with, but I prefer the following method as I think it shows more clearly where blocks start and end:

if ( true )
{
// Do stuff.
}
else
{
}

However, this last one makes me want to vomitseen not just at ASL, but at other places of professional coding:

if ( true ) {
// Do stuff.
} else {
// Do something else.
}

Yuk!

6 thoughts on “The great parenthesis debate

  1. @Grumpy: I didn’t think that you did pudding?

    Pudding was going to be a discussion about whether one should use 0 or ‘null’ when validating pointers, however, that debate seems to be more fierce than the parenthesis one!

  2. You know what I’m going to say…

    if true
    # do stuff
    else
    # do something else
    end

    No brackets, curly or otherwise!

    (And Steve will say…

    if true:
    # do stuff
    else:
    # do something else

    no end either (but shame about the colons)).

  3. I should have specified that this post was concerned with C++ only, however, I can pre-empt your response to this by stating that the short form of conditional code blocks is prohibited under the coding standards.

    Whilst I don’t like this rule, I can also see that it grew out of specific problems arising from the use of conditional code blocks.

  4. @JoJo: personally, I think the brackets-on-their-own-line method visually makes things easier to read. It would be interesting to know _why_ your coding standards are as they are. (My guess is if you can dig back far enough, the person who originally wrote the standard was taught that way.)

    @Chris: you forget the indentation!

Leave a Reply

Your email address will not be published. Required fields are marked *