CODING: switch braces policy for single-line bodies

The current developer pool prefers to always use braces, for the
reasons given in the updated guidance.

This will apply to new code going forward, and does not imply a desire
to do a sweeping pass to change current instances.

Change-Id: If6e157438f222ca805506cc55cd61b969dce63a3
Reviewed-on: https://gerrit.openafs.org/15717
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
Benjamin Kaduk 2024-03-24 19:58:02 -07:00
parent c6129a9895
commit 4a32840b3a

25
CODING
View File

@ -100,29 +100,30 @@ Example:
* like this example. * like this example.
*/ */
Do not use braces on one-line if and loop statements (but if one branch of Always use braces for the bodies of conditionals and loops. This makes
a multi-branch conditional needs braces, use braces for all branches). it easier to follow the logic flow for complicated nested constructs,
and reduces the risk of bugs.
Use: Use:
if (some_condition)
do_some_action();
else
do_something_else();
while (some_condition)
do_something();
Instead of:
if (some_condition) { if (some_condition) {
do_some_action(); do_some_action();
} else {
do_something_else();
} }
while (some_condition) { while (some_condition) {
do_something(); do_something();
} }
Instead of:
if (some_condition)
do_some_action();
while (some_condition)
do_something();
In switch statements, to fall through from one case statement to another, use In switch statements, to fall through from one case statement to another, use
AFS_FALLTHROUGH to mark the intentional fall through. Do not use fall through AFS_FALLTHROUGH to mark the intentional fall through. Do not use fall through
comments (e.g. /* fallthrough */), as some compilers do not recognize them and comments (e.g. /* fallthrough */), as some compilers do not recognize them and