CodingStyle question: multiple statements on a single line

From: Hans Verkuil
Date: Tue Sep 02 2008 - 18:21:24 EST


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
--
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/