Messages in this thread | | | From | Roland Dreier <> | Subject | Re: CodingStyle question: multiple statements on a single line | Date | Tue, 02 Sep 2008 15:34:42 -0700 |
| |
> 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.
| |