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!

Tags:

6 Responses to “The great parenthesis debate”

  1. Grumpy says:

    What happened to pudding?

  2. jojo says:

    @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!

  3. Chris says:

    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)).

  4. jojo says:

    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.

  5. Steve says:

    @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!

  6. jojo says:

    @Steve: The reasoning behind the standard is that it visually makes things easier to read, apparently.

Leave a Reply