All of lore.kernel.org
 help / color / mirror / Atom feed
* CodingStyle question: multiple statements on a single line
@ 2008-09-02 22:20 Hans Verkuil
  2008-09-02 22:34 ` Roland Dreier
  2008-09-03  6:57 ` Frans Meulenbroeks
  0 siblings, 2 replies; 9+ messages in thread
From: Hans Verkuil @ 2008-09-02 22:20 UTC (permalink / raw)
  To: LKML; +Cc: v4l-dvb maintainer list

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-09-03 20:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-02 22:20 CodingStyle question: multiple statements on a single line Hans Verkuil
2008-09-02 22:34 ` Roland Dreier
2008-09-02 23:50   ` Mike Isely
2008-09-03  0:23     ` Randy Dunlap
2008-09-03 12:19     ` Krzysztof Halasa
2008-09-03 18:38     ` Roland Dreier
2008-09-03 20:22       ` Lennart Sorensen
2008-09-03 12:15   ` Krzysztof Halasa
2008-09-03  6:57 ` Frans Meulenbroeks

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.