Source-Changes-HG archive

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

[src/trunk]: src/share/misc Update style around single-line braces according ...



details:   https://anonhg.NetBSD.org/src/rev/c08fce7e3e61
branches:  trunk
changeset: 1012553:c08fce7e3e61
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Aug 02 01:35:07 2020 +0000

description:
Update style around single-line braces according to discussion.

https://mail-index.netbsd.org/tech-userlevel/2020/07/12/msg012536.html
https://mail-index.netbsd.org/tech-kern/2020/07/12/msg026594.html

Retain some examples of technically unnecessary braces that likely
aid legibility from the previous commit.

diffstat:

 share/misc/style |  21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diffs (71 lines):

diff -r 89451aaf91d3 -r c08fce7e3e61 share/misc/style
--- a/share/misc/style  Sun Aug 02 01:17:56 2020 +0000
+++ b/share/misc/style  Sun Aug 02 01:35:07 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: style,v 1.57 2020/08/02 00:20:21 lukem Exp $ */
+/* $NetBSD: style,v 1.58 2020/08/02 01:35:07 riastradh Exp $ */
 
 /*
  * The revision control tag appears first, with a blank line after it.
@@ -30,7 +30,7 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: style,v 1.57 2020/08/02 00:20:21 lukem Exp $");
+__RCSID("$NetBSD: style,v 1.58 2020/08/02 01:35:07 riastradh Exp $");
 
 /*
  * VERY important single-line comments look like this.
@@ -241,8 +241,9 @@
                        errno = 0;
                        num = strtol(optarg, &ep, 10);
                        if (num <= 0 || *ep != '\0' || (errno == ERANGE &&
-                           (num == LONG_MAX || num == LONG_MIN)) )
+                           (num == LONG_MAX || num == LONG_MIN)) ) {
                                errx(1, "illegal number -- %s", optarg);
+                       }
                        break;
                case '?':
                default:
@@ -254,9 +255,9 @@
        argv += optind;
 
        /*
-        * Space after keywords (while, for, return, switch).  No braces are
-        * required for control statements with only a single statement,
-        * unless it's a long statement.
+        * Space after keywords (while, for, return, switch).
+        *
+        * Braces around single-line bodies are optional; use discretion.
         *
         * Forever loops are done with for's, not while's.
         */
@@ -288,15 +289,14 @@
        }
 
        /* Second level indents are four spaces. */
-       while (cnt < 20)
+       while (cnt < 20) {
                z = a + really + long + statement + that + needs + two + lines +
                    gets + indented + four + spaces + on + the + second +
                    and + subsequent + lines;
+       }
 
        /*
         * Closing and opening braces go on the same line as the else.
-        * Don't add braces that aren't necessary except in cases where
-        * there are ambiguity or readability issues.
         */
        if (test) {
                /*
@@ -310,8 +310,9 @@
        } else if (bar) {
                stmt;
                stmt;
-       } else
+       } else {
                stmt;
+       }
 
        /* No spaces after function names. */
        if ((result = function(a1, a2, a3, a4)) == NULL)



Home | Main Index | Thread Index | Old Index