diff --git a/docs/development/CodingStyle.md b/docs/development/CodingStyle.md index 3528d6be62..378a364ff7 100644 --- a/docs/development/CodingStyle.md +++ b/docs/development/CodingStyle.md @@ -30,17 +30,20 @@ Sometimes, for example, you may want other columns and line breaks so it looks l Note2: The Astyle settings have been tested and will produce a nice result. Many files will be changed, mostly to the better but maybe not always, so use with care. ## Curly Braces - -Functions shall have the opening brace at the beginning of the next line. +### Functions +Functions shall have the opening and closing braces at the beginning of the next line, and followed by a line break. ``` int function(int x) { body of function } ``` +### Non-function statement blocks -All non-function statement blocks (if, switch, for) shall have the opening brace last on the same line, with the following statement on the next line. +#### Opening braces +All non-function statement blocks (i.e. `if`, ` switch`, `for`, as well as any others) shall have the opening brace last on the same line, with the following statement on the next line. +#### Closing braces Closing braces shall be but on the line after the last statement in the block. ``` if (x is true) { @@ -62,7 +65,7 @@ default: } ``` -If it is followed by an `else` or `else if` that shall be on the same line, again with the opening brace on the same line. +If the closing brace is followed by an `else` or `else if` that shall be on the same line, again with the opening brace on the same line. ``` if (x is true) { we do y @@ -72,7 +75,7 @@ if (x is true) { ... } ``` - +###Braces are required Omission of "unnecessary" braces in cases where an `if` or `else` block consists only of a single statement is not permissible in any case. These "single statement blocks" are future bugs waiting to happen when more statements are added without enclosing the block in braces. ## Spaces