mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 09:45:37 +03:00
Markdown fixes and added style examples
This commit is contained in:
parent
9ef901f251
commit
290cfebd99
1 changed files with 68 additions and 19 deletions
|
@ -28,14 +28,63 @@ Note2: The Astyle settings have been tested and will produce a nice result. Many
|
||||||
|
|
||||||
## Curly Braces
|
## Curly Braces
|
||||||
Functions shall have the opening brace at the beginning of the next line.
|
Functions shall have the opening brace at the beginning of the next line.
|
||||||
|
```
|
||||||
|
int function(int x)
|
||||||
|
{
|
||||||
|
body of function
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
Closing braces shall be but on the line after the last statement in the block.
|
Closing braces shall be but on the line after the last statement in the block.
|
||||||
|
```
|
||||||
|
if (x is true) {
|
||||||
|
we do y
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
switch (action) {
|
||||||
|
case ADD:
|
||||||
|
return "add";
|
||||||
|
case REMOVE:
|
||||||
|
return "remove";
|
||||||
|
case CHANGE:
|
||||||
|
return "change";
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
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 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 (x is true) {
|
||||||
|
we do y
|
||||||
|
...
|
||||||
|
} else {
|
||||||
|
we do z
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
A single statement after an `if` or an `else` may omit the "unnecessary" braces only when ALL conditional branches have single statements AND you have strong reason to know it will always be that way.
|
A single statement after an `if` or an `else` may omit the "unnecessary" braces only when ALL conditional branches have single statements AND you have strong reason to know it will always be that way.
|
||||||
|
```
|
||||||
|
if (x is true)
|
||||||
|
we do y
|
||||||
|
else
|
||||||
|
we do z
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
if (x is true) {
|
||||||
|
we do y
|
||||||
|
...
|
||||||
|
} else {
|
||||||
|
we do z
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If in doubt, do not omit such "unnecessary" braces.
|
If in doubt, do not omit such "unnecessary" braces.
|
||||||
(Adding a statement to a branch will break the logic if the braces are forgotten and otherwise make the PR longer).
|
(Adding a statement to a branch will break the logic if the braces are forgotten and otherwise make the PR longer).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue