Re: CodingStyle question: multiple statements on a single line
From: Roland Dreier
Date: Tue Sep 02 2008 - 18:34:53 EST
> 2) No, never use the 'if (a) b;' construction. Put 'b;' on the next line
> instead.
This is correct. Always write simple if statements as
if (a)
b;
> And in general, why is this:
>
> if (a) {
> b;
> }
>
> not accepted by the CodingStyle? (At least as I understand it)
The braces take up another line of whitespace, which means less code
fits on the screen. And in simple cases, they don't add anything.
Finally, the vast majority of the kernel leaves the braces off, so they
look funny to people who read a lot of kernel code.
And uniformity counts for a lot: most coding style rules are completely
arbitrary, but having a uniform kernel style makes reading kernel code
much easier.
Keep in mind that common sense always trumps any mechanical rule. So if
there is some case where writing
if (a) {
b;
}
is clearly easier to read than leaving the braces off, then that would
be OK.
- R.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/