LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [patch]clarification of coding style regarding conditional statements with two branches
@ 2007-05-04 7:26 Oliver Neukum
2007-05-04 14:48 ` Jiri Slaby
0 siblings, 1 reply; 6+ messages in thread
From: Oliver Neukum @ 2007-05-04 7:26 UTC (permalink / raw)
To: linux-kernel
Hi,
I suggest that the coding style should state that if either branch of
an 'if' statement needs braces, both branches should use them.
Regards
Oliver
Signed-off-by: Oliver Neukum <oneukum@suse.de>
----
--- a/Documentation/CodingStyle 2007-04-20 13:08:17.000000000 +0200
+++ b/Documentation/CodingStyle 2007-04-20 13:16:14.000000000 +0200
@@ -160,6 +160,21 @@
25-line terminal screens here), you have more empty lines to put
comments on.
+Do not unnecessarily use braces where a single statement will do.
+
+if (condition)
+ action();
+
+This does not apply if one branch of a conditional statement is a single
+statement. Use braces in both branches.
+
+if (condition) {
+ do_this();
+ do_that();
+} else {
+ otherwise();
+}
+
3.1: Spaces
Linux kernel style for use of spaces depends (mostly) on
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch]clarification of coding style regarding conditional statements with two branches
2007-05-04 7:26 [patch]clarification of coding style regarding conditional statements with two branches Oliver Neukum
@ 2007-05-04 14:48 ` Jiri Slaby
2007-05-04 15:29 ` Oliver Neukum
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Jiri Slaby @ 2007-05-04 14:48 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-kernel
Oliver Neukum napsal(a):
> Hi,
>
> I suggest that the coding style should state that if either branch of
> an 'if' statement needs braces, both branches should use them.
>
> Regards
> Oliver
> Signed-off-by: Oliver Neukum <oneukum@suse.de>
> ----
>
> --- a/Documentation/CodingStyle 2007-04-20 13:08:17.000000000 +0200
> +++ b/Documentation/CodingStyle 2007-04-20 13:16:14.000000000 +0200
> @@ -160,6 +160,21 @@
> 25-line terminal screens here), you have more empty lines to put
> comments on.
>
> +Do not unnecessarily use braces where a single statement will do.
> +
> +if (condition)
> + action();
> +
> +This does not apply if one branch of a conditional statement is a single
> +statement. Use braces in both branches.
Why, what's wrong with
if (condition) {
do_this();
do_that();
} else
otherwise();
? It's more readable/nicer in my eyes than
> +if (condition) {
> + do_this();
> + do_that();
> +} else {
> + otherwise();
> +}
> +
and not only in mine according to fast grep.
regards,
--
http://www.fi.muni.cz/~xslaby/ Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8 22A0 32CC 55C3 39D4 7A7E
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch]clarification of coding style regarding conditional statements with two branches
2007-05-04 14:48 ` Jiri Slaby
@ 2007-05-04 15:29 ` Oliver Neukum
2007-05-04 16:24 ` Jiri Slaby
2007-05-04 16:16 ` Krzysztof Halasa
2007-05-04 21:16 ` Jan Engelhardt
2 siblings, 1 reply; 6+ messages in thread
From: Oliver Neukum @ 2007-05-04 15:29 UTC (permalink / raw)
To: Jiri Slaby; +Cc: linux-kernel
Am Freitag, 4. Mai 2007 16:48 schrieb Jiri Slaby:
> Why, what's wrong with
> if (condition) {
> do_this();
> do_that();
> } else
> otherwise();
>
> ? It's more readable/nicer in my eyes than
Than I am afraid we need to agree to disagree. But then I would
insist that neither side give the other a hard to time over this issue.
Regards
Oliver
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch]clarification of coding style regarding conditional statements with two branches
2007-05-04 14:48 ` Jiri Slaby
2007-05-04 15:29 ` Oliver Neukum
@ 2007-05-04 16:16 ` Krzysztof Halasa
2007-05-04 21:16 ` Jan Engelhardt
2 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Halasa @ 2007-05-04 16:16 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Oliver Neukum, linux-kernel
Jiri Slaby <jirislaby@gmail.com> writes:
> Why, what's wrong with
> if (condition) {
> do_this();
> do_that();
> } else
> otherwise();
>
> ? It's more readable/nicer in my eyes than
I think so. And it means less lines #.
>> +if (condition) {
>> + do_this();
>> + do_that();
>> +} else {
>> + otherwise();
>> +}
Exception:
if (x) {
if (y)
foo1();
else
foo2();
} else
bar();
The braces after if(x) are needed so nobody thinks it's:
if (x)
if (y)
foo1();
else
foo2();
else
bar();
--
Krzysztof Halasa
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch]clarification of coding style regarding conditional statements with two branches
2007-05-04 15:29 ` Oliver Neukum
@ 2007-05-04 16:24 ` Jiri Slaby
0 siblings, 0 replies; 6+ messages in thread
From: Jiri Slaby @ 2007-05-04 16:24 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-kernel
Oliver Neukum napsal(a):
> Am Freitag, 4. Mai 2007 16:48 schrieb Jiri Slaby:
>> Why, what's wrong with
>> if (condition) {
>> do_this();
>> do_that();
>> } else
>> otherwise();
>>
>> ? It's more readable/nicer in my eyes than
>
> Than I am afraid we need to agree to disagree. But then I would
> insist that neither side give the other a hard to time over this issue.
Then I would just let it undefined to let subsys maintainers (or coders
themselves) to decide what they want in their subtree like ton of other things...
regards,
--
http://www.fi.muni.cz/~xslaby/ Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8 22A0 32CC 55C3 39D4 7A7E
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch]clarification of coding style regarding conditional statements with two branches
2007-05-04 14:48 ` Jiri Slaby
2007-05-04 15:29 ` Oliver Neukum
2007-05-04 16:16 ` Krzysztof Halasa
@ 2007-05-04 21:16 ` Jan Engelhardt
2 siblings, 0 replies; 6+ messages in thread
From: Jan Engelhardt @ 2007-05-04 21:16 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Oliver Neukum, linux-kernel
On May 4 2007 16:48, Jiri Slaby wrote:
>>
>> +Do not unnecessarily use braces where a single statement will do.
>> +
>> +if (condition)
>> + action();
>> +
>> +This does not apply if one branch of a conditional statement is a single
>> +statement. Use braces in both branches.
>
>Why, what's wrong with
>if (condition) {
> do_this();
> do_that();
>} else
> otherwise();
>
>? It's more readable/nicer in my eyes.
I'll just point to an opinion:
http://lkml.org/lkml/2006/9/5/36 , lower half. ("Secondly, whenever...")
Jan
--
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-05-04 21:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-04 7:26 [patch]clarification of coding style regarding conditional statements with two branches Oliver Neukum
2007-05-04 14:48 ` Jiri Slaby
2007-05-04 15:29 ` Oliver Neukum
2007-05-04 16:24 ` Jiri Slaby
2007-05-04 16:16 ` Krzysztof Halasa
2007-05-04 21:16 ` Jan Engelhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).