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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]