git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] Documenation update: use of braces in if/else if/else chain
@ 2012-06-10 17:26 Leila Muhtasib
  2012-06-10 20:22 ` Jonathan Nieder
  0 siblings, 1 reply; 3+ messages in thread
From: Leila Muhtasib @ 2012-06-10 17:26 UTC (permalink / raw)
  To: git; +Cc: Leila Muhtasib


Signed-off-by: Leila Muhtasib <muhtasib@gmail.com>
---
Does the below more accruately represent the coding guidelines?
I can modify it, if it doesn't.

Thanks,
Leila


 Documentation/CodingGuidelines |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 4557711..ea90521 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -117,9 +117,26 @@ For C programs:
 
    is frowned upon.  A gray area is when the statement extends
    over a few lines, and/or you have a lengthy comment atop of
-   it.  Also, like in the Linux kernel, if there is a long list
-   of "else if" statements, it can make sense to add braces to
-   single line blocks.
+   it.  Also, like in the Linux kernel, if one of the
+   "if/else if/else" chain has a multiple statement block, use {}
+   even for a single statement block in that chain. And "else"
+   should come on the same line as the closing "}" of its "if" block.
+
+	//correct
+	if (bla) {
+		x = 1;
+		...
+	} else {
+		x = 2;
+	}
+
+	//incorrect
+	if (bla) {
+		x = 1;
+		...
+	}
+	else
+		x = 2;
 
  - We try to avoid assignments inside if().
 
-- 
1.7.7.5 (Apple Git-26)

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

end of thread, other threads:[~2012-06-10 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-10 17:26 [PATCH/RFC] Documenation update: use of braces in if/else if/else chain Leila Muhtasib
2012-06-10 20:22 ` Jonathan Nieder
2012-06-10 20:52   ` Leila

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).