lkml.org 
[lkml]   [2008]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: CodingStyle question: multiple statements on a single line
Date
 > 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.


\
 
 \ /
  Last update: 2008-09-03 00:37    [W:0.135 / U:0.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site