From 79bfa181dd837c5949bcfcf3fb01b7fbecc8b44e Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 22 Jan 2021 15:51:35 -0800 Subject: [PATCH 1/3] Clarifies and clean-up Formatting style > Curly braces - adds `code` formatting to some keywords - adds some more clarifications to existing style rules. --- docs/development/CodingStyle.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/development/CodingStyle.md b/docs/development/CodingStyle.md index 3528d6be62..c840b06453 100644 --- a/docs/development/CodingStyle.md +++ b/docs/development/CodingStyle.md @@ -31,7 +31,7 @@ Note2: The Astyle settings have been tested and will produce a nice result. Many ## Curly Braces -Functions shall have the opening brace at the beginning of the next line. +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) { @@ -39,7 +39,8 @@ int function(int x) } ``` -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. +### Non-function blocks +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 shall be but on the line after the last statement in the block. ``` @@ -62,7 +63,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 +73,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 From 5e5748c99a63f9a59587c3cb9efe9b8d8e2a8555 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 22 Jan 2021 15:58:17 -0800 Subject: [PATCH 2/3] removes unintentional heading --- docs/development/CodingStyle.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/development/CodingStyle.md b/docs/development/CodingStyle.md index c840b06453..b9d6b0b9f4 100644 --- a/docs/development/CodingStyle.md +++ b/docs/development/CodingStyle.md @@ -39,7 +39,6 @@ int function(int x) } ``` -### Non-function blocks 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 shall be but on the line after the last statement in the block. From 7641bdcc9142a249a20641a8fd87bc124e2b5dd9 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 22 Jan 2021 16:01:58 -0800 Subject: [PATCH 3/3] adds additional headings to Curly braces section Adds proposed sub headings to Formatting Style > Curly Braces section --- docs/development/CodingStyle.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/development/CodingStyle.md b/docs/development/CodingStyle.md index b9d6b0b9f4..378a364ff7 100644 --- a/docs/development/CodingStyle.md +++ b/docs/development/CodingStyle.md @@ -30,7 +30,7 @@ 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 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) @@ -38,9 +38,12 @@ int function(int x) body of function } ``` +### Non-function statement blocks +#### 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) {