]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[master] revise style guide information on bracing
authorEvan Hunt <each@isc.org>
Thu, 5 Oct 2017 18:28:00 +0000 (11:28 -0700)
committerEvan Hunt <each@isc.org>
Thu, 5 Oct 2017 18:28:00 +0000 (11:28 -0700)
doc/dev/style.md

index a29923d213b19e5c8bc1ae4ae6abb25f56a4d970..6ccd899fbbbdae30bc356f72e8b34962a27995c4 100644 (file)
@@ -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
 else clause.
 
-Generally speaking, when a control statement (e.g., `if`, `for` or `while`) has
-only a single action associated with it, then no bracing is used around the
-statement.  Exceptions include when the compiler would complain about an
-ambiguous else clause, or when extra bracing improves readability or
-safety.
+If a controlling statement (e.g., `if`, `while`, or `for`) or a function
+header at the start of a block of code is all on one line, then the opening
+brace should at the end of that line. If the controlling statement occupies
+multiple lines, then the opening brace should be on the next line by itself.
+
+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:
 
@@ -279,8 +285,9 @@ Good:
                if (i > 0) {
                        printf("yes\\n");
                        i = 0;
-               } else
+               } else {
                        printf("no\\n");
+               }
        }
 
 Bad:
@@ -288,6 +295,8 @@ Bad:
        void f(int i)
          {
            if(i<0){i=0;printf("was negative\\n");}
+           if (i == 0)
+               printf("no\\n");
            if (i > 0)
              {
                printf("yes\\n");