From 4a32840b3a84a5a20d906cc641bf49b33e838b44 Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Sun, 24 Mar 2024 19:58:02 -0700 Subject: [PATCH] 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 Reviewed-by: Andrew Deason Reviewed-by: Michael Meffie Reviewed-by: Mark Vitale Reviewed-by: Benjamin Kaduk Tested-by: Benjamin Kaduk --- CODING | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/CODING b/CODING index 66fdc02086..1a2abd5500 100644 --- a/CODING +++ b/CODING @@ -100,29 +100,30 @@ Example: * like this example. */ -Do not use braces on one-line if and loop statements (but if one branch of -a multi-branch conditional needs braces, use braces for all branches). +Always use braces for the bodies of conditionals and loops. This makes +it easier to follow the logic flow for complicated nested constructs, +and reduces the risk of bugs. Use: - if (some_condition) - do_some_action(); - else - do_something_else(); - - while (some_condition) - do_something(); - -Instead of: - if (some_condition) { do_some_action(); + } else { + do_something_else(); } while (some_condition) { 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 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