mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 06:50:12 +00:00
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:
parent
c6129a9895
commit
4a32840b3a
25
CODING
25
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
|
||||
|
Loading…
Reference in New Issue
Block a user