[libvirt] [PATCH v2 19/22] docs: Adjust contributor guidelines about curly brackets

Eric Blake eblake at redhat.com
Thu Nov 13 23:59:16 UTC 2014


On 11/13/2014 07:37 AM, Martin Kletzander wrote:
> 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 at redhat.com>
> ---
>  HACKING              | 8 ++++----
>  docs/hacking.html.in | 4 ++--
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 

> +++ b/docs/hacking.html.in
> @@ -462,8 +462,8 @@
> 
>      <p>
>        Omit the curly braces around an <code>if</code>, <code>while</code>,
> -      <code>for</code> etc. body only
> -      when that body occupies a single line.  In every other case we require
> +      <code>for</code> 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-<i>statement</i> loop: each has only one <i>line</i> in its body.
>      </p>

I think we want a few more examples, and mention that the ultimate
measure of whether {} are required or prohibited is whether syntax-check
complains.

if (condition1 &&
    condition2) { // multi-line, at same indentation, {} required
    statement();
}

if (condition1(arg1,
               arg2)) // indentation makes it obvious it is single line,
    statement();      // {} is optional (not enforced either way)

if (condition1)
    statement(); // single-line; {} is forbidden


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 539 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20141113/639362d5/attachment-0001.sig>


More information about the libvir-list mailing list