[PATCH REVIEW] fix brace placement for readability

Michael Adam obnox at samba.org
Wed Oct 17 13:20:06 MDT 2012


On 2012-10-17 at 20:55 +0200, Christian Ambach wrote:
> On 10/17/2012 02:44 PM, simo wrote:
> 
> >I hate it too, I though braces on new line were allowed exclusively for
> >function declarations in our guideline.
> 
> I thought the same and I would rather change the guidelines than the
> gazillion places that use the format with the brace at the end of same line.

As with other rules, we usually don't change existing code to
adhere to guidelines, unless we work in the area anyways.
Which is why I did this patch.

I really like this a rule a lot.
Let me illustrate with an example:

Compare this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if (some_really_nasty_long_condition_number_1 &&
            some_really_nasty_long_condition_number_2 &&
            some_really_nasty_long_condition_number_3 &&
            some_really_nasty_long_condition_number_4 &&
            some_really_nasty_long_condition_number_5 &&
            some_really_nasty_long_condition_number_6 &&
            some_really_nasty_long_condition_number_7 &&
            some_really_nasty_long_condition_number_8 &&
            some_really_nasty_long_condition_number_9) {
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
        }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

to this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if (some_really_nasty_long_condition_number_1 &&
            some_really_nasty_long_condition_number_2 &&
            some_really_nasty_long_condition_number_3 &&
            some_really_nasty_long_condition_number_4 &&
            some_really_nasty_long_condition_number_5 &&
            some_really_nasty_long_condition_number_6 &&
            some_really_nasty_long_condition_number_7 &&
            some_really_nasty_long_condition_number_8 &&
            some_really_nasty_long_condition_number_9)
        {
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
                print("some rather longish message to be printed\n");
        }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For my perception, in the first example, the opening brace is visually
lost and the end of the conditions and start of the body is not well
visible, while in the second example, due to the brace on its own line,
this clearly stands out.

In the first example, the opening brace ecsapes the eye, and if the closing
is down below the end of the editor window, it could even look like a badly
formatted if statement with just a single line for body, and without enclosing
 braces.

So, I really love this exception from the general rule,
but hey, it is "just" a formatting rule, so if the majority would like
to change it, I'd yield. ;)

Cheers - Michael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 206 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20121017/3a72161d/attachment.pgp>


More information about the samba-technical mailing list