public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] Codingstyle: allow omitting braces for all single statement branches
@ 2009-11-26  9:26 Uwe Kleine-König
  2009-11-26 14:52 ` Peter Zijlstra
  2009-11-26 16:11 ` Stefan Richter
  0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2009-11-26  9:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Junio C Hamano, Randy Dunlap, Teemu Likonen, Jiri Kosina,
	Dan Carpenter, Martin Olsson, linux-doc

Grepping for "} else$" in v2.6.32-rc8 yields 6440 hits.  So this seems
to be common practice and should be allowed.  checkpatch doesn't warn
about both variants.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Cc: Teemu Likonen <tlikonen@iki.fi>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Dan Carpenter <error27@gmail.com>
Cc: Martin Olsson <martin@minimum.se>
Cc: linux-doc@vger.kernel.org
---
 Documentation/CodingStyle |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 8bb3723..84563c6 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -168,15 +168,23 @@ 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();
-}
+If not all branches of a conditional statement are single statements you might
+use braces for both branches.
+
+	if (condition) {
+		do_this();
+		do_that();
+	} else
+		otherwise();
+
+or
+
+	if (condition) {
+		do_this();
+		do_that();
+	} else {
+		otherwise();
+	}
 
 		3.1:  Spaces
 
-- 
1.6.5.2


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

* Re: [PATCH RFC] Codingstyle: allow omitting braces for all single statement branches
  2009-11-26  9:26 [PATCH RFC] Codingstyle: allow omitting braces for all single statement branches Uwe Kleine-König
@ 2009-11-26 14:52 ` Peter Zijlstra
  2009-11-26 16:11 ` Stefan Richter
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2009-11-26 14:52 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-kernel, Junio C Hamano, Randy Dunlap, Teemu Likonen,
	Jiri Kosina, Dan Carpenter, Martin Olsson, linux-doc,
	Andrew Morton

On Thu, 2009-11-26 at 10:26 +0100, Uwe Kleine-König wrote:

> -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();
> -}
> +If not all branches of a conditional statement are single statements you might
> +use braces for both branches.
> +
> +	if (condition) {
> +		do_this();
> +		do_that();
> +	} else
> +		otherwise();
> +
> +or
> +
> +	if (condition) {
> +		do_this();
> +		do_that();
> +	} else {
> +		otherwise();
> +	}
>  
>  		3.1:  Spaces

Andrew recently objected to this pattern, and I tend to agree with him
although I might be guilty of a few such cases myself.


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

* Re: [PATCH RFC] Codingstyle: allow omitting braces for all single statement branches
  2009-11-26  9:26 [PATCH RFC] Codingstyle: allow omitting braces for all single statement branches Uwe Kleine-König
  2009-11-26 14:52 ` Peter Zijlstra
@ 2009-11-26 16:11 ` Stefan Richter
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Richter @ 2009-11-26 16:11 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-kernel, Junio C Hamano, Randy Dunlap, Teemu Likonen,
	Jiri Kosina, Dan Carpenter, Martin Olsson, linux-doc

Uwe Kleine-König wrote:
> Grepping for "} else$" in v2.6.32-rc8 yields 6440 hits.  So this seems
> to be common practice and should be allowed.

Flawed reasoning.  Is this in new and otherwise stylistically
well-written code?  Or did you perhaps grep in old code or even in staging?

> checkpatch doesn't warn about both variants.

What checkpatch does/ can do, or doesn't, is only indirectly related to
good style or canonical style.

> --- a/Documentation/CodingStyle
> +++ b/Documentation/CodingStyle
> @@ -168,15 +168,23 @@ 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();
> -}
> +If not all branches of a conditional statement are single statements you might
> +use braces for both branches.
> +
> +	if (condition) {
> +		do_this();
> +		do_that();
> +	} else
> +		otherwise();
> +
> +or
> +
> +	if (condition) {
> +		do_this();
> +		do_that();
> +	} else {
> +		otherwise();
> +	}
>  
>  		3.1:  Spaces
>  

Either don't remove the existing paragraph, or remove it --- but do not
add your new either-or paragraph.  If you consider both variants to be
OK, you don't need to bloat the style guide by documenting them both.
There is no third or fourth alternative.
-- 
Stefan Richter
-=====-==--= =-== ==-=-
http://arcgraph.de/sr/

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

end of thread, other threads:[~2009-11-26 16:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-26  9:26 [PATCH RFC] Codingstyle: allow omitting braces for all single statement branches Uwe Kleine-König
2009-11-26 14:52 ` Peter Zijlstra
2009-11-26 16:11 ` Stefan Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox