mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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 <mkletzan@redhat.com>
This commit is contained in:
parent
f5e65e4b71
commit
a9d07d33a0
18
HACKING
18
HACKING
@ -370,14 +370,20 @@ although use of a semicolon is not currently rejected.
|
|||||||
|
|
||||||
Curly braces
|
Curly braces
|
||||||
============
|
============
|
||||||
Omit the curly braces around an "if", "while", "for" etc. body only when that
|
Omit the curly braces around an "if", "while", "for" etc. body only when both
|
||||||
body occupies a single line. In every other case we require the braces. This
|
that body and the condition itself occupy a single line. In every other case
|
||||||
ensures that it is trivially easy to identify a single-'statement' loop: each
|
we require the braces. This ensures that it is trivially easy to identify a
|
||||||
has only one 'line' in its body.
|
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) // one-line body -> omitting curly braces is ok
|
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();
|
single_line_stmt();
|
||||||
|
|
||||||
However, the moment your loop/if/else body extends on to a second line, for
|
However, the moment your loop/if/else body extends on to a second line, for
|
||||||
|
@ -462,17 +462,26 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
Omit the curly braces around an <code>if</code>, <code>while</code>,
|
Omit the curly braces around an <code>if</code>, <code>while</code>,
|
||||||
<code>for</code> etc. body only
|
<code>for</code> etc. body only when both that body and the condition
|
||||||
when that body occupies a single line. In every other case we require
|
itself occupy a single line. In every other case we require
|
||||||
the braces. This ensures that it is trivially easy to identify a
|
the braces. This ensures that it is trivially easy to identify a
|
||||||
single-<i>statement</i> loop: each has only one <i>line</i> in its body.
|
single-<i>statement</i> loop: each has only one <i>line</i> in its body.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
|
||||||
Omitting braces with a single-line body is fine:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
while (expr) // one-line body -> omitting curly braces is ok
|
while (expr) // single line body; {} is forbidden
|
||||||
|
single_line_stmt();
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
while (expr(arg1,
|
||||||
|
arg2)) // indentation makes it obvious it is single line,
|
||||||
|
single_line_stmt(); // {} is optional (not enforced either way)
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
while (expr1 &&
|
||||||
|
expr2) // multi-line, at same indentation, {} required
|
||||||
single_line_stmt();
|
single_line_stmt();
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user