tech-userlevel archive

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

Re: style change: explicitly permit braces for single statements



On Sun, 12 Jul 2020, Valery Ushakov wrote:

Luke Mewburn <lukem%netbsd.org@localhost> wrote:

I propose that the NetBSD C style guide in to /usr/share/misc/style
is reworded to more explicitly permit braces around single statements,
instead of the current discourgement.

IMHO, permitting braces to be consistently used:
- Adds to clarity of intent.
- Aids code review.
- Avoids gotofail: https://en.wikipedia.org/wiki/Unreachable_code#goto_fail_bug

Yes, please.

My primary reason to prefer them is minimizing diffs when you do need
to add another statement.  If the OTBS opening brace is already there
then you don't need to spend any mental effort on parsing:

-	if (complex condition full of alphabet soup and punctuation)
+	if (complex condition full of alphabet suop and punctuation) {

to check whether the condition was changed or if it's just the brace.

Another +1 here.  The "add another statement" is frequently "add a
debug_printf()" and many is the time i've broken an if statement by
adding debug code.


+--------------------+--------------------------+-----------------------+
| Paul Goyette       | PGP Key fingerprint:     | E-mail addresses:     |
| (Retired)          | FA29 0E3B 35AF E8AE 6651 | paul%whooppee.com@localhost     |
| Software Developer | 0786 F758 55DE 53BA 7731 | pgoyette%netbsd.org@localhost   |
+--------------------+--------------------------+-----------------------+


Home | Main Index | Thread Index | Old Index