From: Martin Kletzander Date: Thu, 13 Nov 2014 13:56:53 +0000 (+0100) Subject: docs: Adjust contributor guidelines about curly brackets X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a9d07d33a078c34020916f1f0c5dc8720310e595;p=libvirt.git docs: Adjust contributor guidelines about curly brackets After recent discussion it looks like curly brackets around one-line bodies are preferred if the preceding condition is, itself, multiline. Signed-off-by: Martin Kletzander --- diff --git a/HACKING b/HACKING index 8f42e51270..0be13bb86f 100644 --- a/HACKING +++ b/HACKING @@ -370,14 +370,20 @@ although use of a semicolon is not currently rejected. Curly braces ============ -Omit the curly braces around an "if", "while", "for" etc. body only when that -body occupies a single line. In every other case we require the braces. This -ensures that it is trivially easy to identify a single-'statement' loop: each -has only one 'line' in its body. +Omit the curly braces around an "if", "while", "for" etc. body only when both +that body and the condition itself occupy a single line. In every other case +we require the braces. This ensures that it is trivially easy to identify a +single-'statement' loop: each has only one 'line' in its body. -Omitting braces with a single-line body is fine: + while (expr) // single line body; {} is forbidden + single_line_stmt(); + + while (expr(arg1, + arg2)) // indentation makes it obvious it is single line, + single_line_stmt(); // {} is optional (not enforced either way) - while (expr) // one-line body -> omitting curly braces is ok + while (expr1 && + expr2) // multi-line, at same indentation, {} required single_line_stmt(); However, the moment your loop/if/else body extends on to a second line, for diff --git a/docs/hacking.html.in b/docs/hacking.html.in index b1553a5c5f..32ebd8e0ac 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -462,17 +462,26 @@

Omit the curly braces around an if, while, - for etc. body only - when that body occupies a single line. In every other case we require + for etc. body only when both that body and the condition + itself occupy a single line. In every other case we require the braces. This ensures that it is trivially easy to identify a single-statement loop: each has only one line in its body.

-

- Omitting braces with a single-line body is fine: -

-  while (expr) // one-line body -> omitting curly braces is ok
+  while (expr)             // single line body; {} is forbidden
+      single_line_stmt();
+
+ +
+  while (expr(arg1,
+              arg2))      // indentation makes it obvious it is single line,
+      single_line_stmt(); // {} is optional (not enforced either way)
+
+ +
+  while (expr1 &&
+         expr2)           // multi-line, at same indentation, {} required
       single_line_stmt();