lkml.org 
[lkml]   [2008]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectCodingStyle question: multiple statements on a single line
Date
Hi all,

On the v4l-dvb list there has been confusion on how to interpret the
following in the CodingStyle document:

"Don't put multiple statements on a single line unless you have
something to hide:

if (condition) do_this;
do_something_everytime;

Don't put multiple assignments on a single line either. Kernel coding
style is super simple. Avoid tricky expressions."

Does this mean:

1) Yes, after an 'if' you can put a single statement like this:

if (a) b;

2) No, never use the 'if (a) b;' construction. Put 'b;' on the next line
instead.

It's the 'have something to hide' part that confuses people: is this
literal or is this sarcastic? This should be reworded to whatever is
really meant.

And in general, why is this:

if (a) {
b;
}

not accepted by the CodingStyle? (At least as I understand it)

Many people find this more readable and certainly safer. Certainly in
cases like this:

for (...)
for (...)
statement;

I would really prefer to have curly brackets as that is much clearer. I
would suggest that having curly brackets around a single statement is
made optional. Especially in view of the sentence 'Avoid tricky
expressions' I would say that this:

if (a)
b;

is definitely trickier than:

if (a) {
b;
}

All it takes is a single indentation error to get into trouble here.

Regards,

Hans


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