-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify braces usages in CODING_GUIDELINES #8640
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it is easier to specify in which cases braces should be omitted:
if condition is placed in one line and every branch bodies consist of one statement and occupy one line.
if (a < b)
doSomething(a);
// or
if (a < b)
doSomething(a);
else if (a > b)
doSomething(b);
else
doSomethingElse();
I see no exceptions from this very simple rule. What do you say?
OK, I've updated the guide, please take a look. |
CODING_GUIDELINES.md
Outdated
@@ -343,4 +352,5 @@ i++, j--; // No | |||
8. If commit fixes a reported issue, mention it in the message body (e.g. `Closes #4134.`) | |||
|
|||
### 11. Not covered above ### | |||
If something isn't covered above, just follow the same style the file you are editing has. If that particular detail isn't present in the file you are editing, then use whatever the rest of the project uses. | |||
If something isn't covered above, just follow the same style the file you are editing has. | |||
*This gudie is not exhaustive and the style for a particular piece of code not specified here will be determined by project members on code review.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: gudie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks fixed.
CODING_GUIDELINES.md
Outdated
* If some branch needs braces then all others should use them. Unless you have multiple `else if` in a row and the one needing the braces is only for a very small sub-block of code. | ||
* Another exception would be when we have nested if blocks or generally multiple levels of code that affect code readability. | ||
#### f. Acceptable conditions to omit braces #### | ||
When every `if`/`else` body statement occupy only one line: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still insist on the second condition I suggested before: the condition statement should occupy only one line too. Or do you have another opinion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I updated the sentence, see if now is clearer.
a64ef3a
to
2ac7bda
Compare
CODING_GUIDELINES.md
Outdated
* If some branch needs braces then all others should use them. Unless you have multiple `else if` in a row and the one needing the braces is only for a very small sub-block of code. | ||
* Another exception would be when we have nested if blocks or generally multiple levels of code that affect code readability. | ||
#### f. Acceptable conditions to omit braces #### | ||
When the conditional statement in `if`/`else` has only one line and its body occupy only one line: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loops should follow these rules as well.
And you forgot to mention "If some branch needs braces then all others should use them."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
Merge "Curly braces" & "If blocks" sections into "New lines & curly braces" section. Add note about the list is not exhaustive and style can be determine on code review.
Thanks! |
No description provided.