mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 18:19:42 +00:00
[master] revise style guide information on bracing
This commit is contained in:
parent
3f3b51e7af
commit
1e14ea024a
@ -266,11 +266,17 @@ braces should not be on the same line as the opening or closing brace. A
|
|||||||
closing brace should be the only thing on the line, unless it's part of an
|
closing brace should be the only thing on the line, unless it's part of an
|
||||||
else clause.
|
else clause.
|
||||||
|
|
||||||
Generally speaking, when a control statement (e.g., `if`, `for` or `while`) has
|
If a controlling statement (e.g., `if`, `while`, or `for`) or a function
|
||||||
only a single action associated with it, then no bracing is used around the
|
header at the start of a block of code is all on one line, then the opening
|
||||||
statement. Exceptions include when the compiler would complain about an
|
brace should at the end of that line. If the controlling statement occupies
|
||||||
ambiguous else clause, or when extra bracing improves readability or
|
multiple lines, then the opening brace should be on the next line by itself.
|
||||||
safety.
|
|
||||||
|
Historically, when a controlling statement such as `if` or `else` had
|
||||||
|
only a single action associated with it, then BIND style specified that
|
||||||
|
no bracing was to used around that action. This has been revised: in
|
||||||
|
newly added code, braces are now preferred around all control statement
|
||||||
|
code blocks. Note that legacy code has not yet been udpated to adhere to
|
||||||
|
this.
|
||||||
|
|
||||||
Good:
|
Good:
|
||||||
|
|
||||||
@ -279,15 +285,18 @@ Good:
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
printf("yes\\n");
|
printf("yes\\n");
|
||||||
i = 0;
|
i = 0;
|
||||||
} else
|
} else {
|
||||||
printf("no\\n");
|
printf("no\\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Bad:
|
Bad:
|
||||||
|
|
||||||
void f(int i)
|
void f(int i)
|
||||||
{
|
{
|
||||||
if(i<0){i=0;printf("was negative\\n");}
|
if(i<0){i=0;printf("was negative\\n");}
|
||||||
|
if (i == 0)
|
||||||
|
printf("no\\n");
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
printf("yes\\n");
|
printf("yes\\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user