Module Name: src Committed By: riastradh Date: Sun Aug 2 01:35:07 UTC 2020
Modified Files: src/share/misc: style Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/share/misc/style Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/misc/style diff -u src/share/misc/style:1.57 src/share/misc/style:1.58 --- src/share/misc/style:1.57 Sun Aug 2 00:20:21 2020 +++ src/share/misc/style Sun Aug 2 01:35:07 2020 @@ -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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) } /* 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 @@ main(int argc, char *argv[]) } else if (bar) { stmt; stmt; - } else + } else { stmt; + } /* No spaces after function names. */ if ((result = function(a1, a2, a3, a4)) == NULL)