From 07b8ffa655590d3ada2bf0a159d2383eab44709e Mon Sep 17 00:00:00 2001 From: riastradh Date: Sun, 2 Aug 2020 01:35:07 +0000 Subject: [PATCH] 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. --- share/misc/style | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/share/misc/style b/share/misc/style index 49c15be5b3e5..694c6a93dc96 100644 --- a/share/misc/style +++ b/share/misc/style @@ -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 __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)