Skip to content
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

Merged
merged 1 commit into from
Apr 1, 2018

Conversation

Chocobo1
Copy link
Member

No description provided.

Copy link
Member

@glassez glassez left a 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?

@Chocobo1
Copy link
Member Author

I see no exceptions from this very simple rule. What do you say?

OK, I've updated the guide, please take a look.

@@ -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.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: gudie

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks fixed.

* 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:
Copy link
Member

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?

Copy link
Member Author

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.

@Chocobo1 Chocobo1 force-pushed the guide2 branch 2 times, most recently from a64ef3a to 2ac7bda Compare March 28, 2018 12:15
* 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:
Copy link
Member

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."

Copy link
Member Author

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.
@Chocobo1 Chocobo1 merged commit e90be67 into qbittorrent:master Apr 1, 2018
@Chocobo1 Chocobo1 deleted the guide2 branch April 1, 2018 10:16
@Chocobo1
Copy link
Member Author

Chocobo1 commented Apr 1, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants