-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Require braces #623
Require braces #623
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.
Thanks, this generally looks good. I don't think I had any major comments.
Co-authored-by: Richard Smith <[email protected]>
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.
Responding to comments
Co-authored-by: Richard Smith <[email protected]>
Co-authored-by: Richard Smith <[email protected]>
(comment pass, responded on topic but forgot to do a review) |
I was moving #655 to draft and remembered |
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.
Really sorry about the delay here... I had several comments and apparently didn't mash the "send" button. =[[[ Hopefully all easy changes just adding information. I've tried to make it very clear what I tihnk is useful to add, and I'm not expecting this to change the outcome of anything.
proposals/p0623.md
Outdated
Some modern languages require braces, including Go, Rust, and Swift. Kotlin is | ||
an example which does not. Note some which require braces make parentheses | ||
optional. |
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.
Seems worth including as background the CERT rule:
https://wiki.sei.cmu.edu/confluence/display/c/EXP19-C.+Use+braces+for+the+body+of+an+if%2C+for%2C+or+while+statement
And the blog post about goto fail;
: https://www.imperialviolet.org/2014/02/22/applebug.html
FWIW, I'm not suggesting that goto fail;
should be a strong rationale for this pattern, but I do think it should be addressed explicitly as it is often cited as a reason for this change. FWIW, I agree with @zygoloid below that simplifying the language grammar seems like a strong motivation. I actually like the summary of the importance of braces here in the blog post:
Maybe the coding style contributed to this by allowing ifs without braces, but one can have incorrect indentation with braces too, so that doesn't seem terribly convincing to me.
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.
Seems worth including as background the CERT rule:
https://wiki.sei.cmu.edu/confluence/display/c/EXP19-C.+Use+braces+for+the+body+of+an+if%2C+for%2C+or+while+statement
Linked.
And the blog post about
goto fail;
: https://www.imperialviolet.org/2014/02/22/applebug.html
Added, moved up the link that was in rationale.
FWIW, I'm not suggesting that
goto fail;
should be a strong rationale for this pattern, but I do think it should be addressed explicitly as it is often cited as a reason for this change. FWIW, I agree with @zygoloid below that simplifying the language grammar seems like a strong motivation. I actually like the summary of the importance of braces here in the blog post:Maybe the coding style contributed to this by allowing ifs without braces, but one can have incorrect indentation with braces too, so that doesn't seem terribly convincing to me.
Are you saying to remove the mention of goto fail
from the rationale? Do you want this sentence somewhere in particular?
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.
Nah, I'm happy mentioning it, I just didn't want to overstate its importance. I've suggested a place where it could even be included in the disadvantages section, but that's optional given the comment in the rationale. Up to you.
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.
Addressing comments
proposals/p0623.md
Outdated
Some modern languages require braces, including Go, Rust, and Swift. Kotlin is | ||
an example which does not. Note some which require braces make parentheses | ||
optional. |
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.
Seems worth including as background the CERT rule:
https://wiki.sei.cmu.edu/confluence/display/c/EXP19-C.+Use+braces+for+the+body+of+an+if%2C+for%2C+or+while+statement
Linked.
And the blog post about
goto fail;
: https://www.imperialviolet.org/2014/02/22/applebug.html
Added, moved up the link that was in rationale.
FWIW, I'm not suggesting that
goto fail;
should be a strong rationale for this pattern, but I do think it should be addressed explicitly as it is often cited as a reason for this change. FWIW, I agree with @zygoloid below that simplifying the language grammar seems like a strong motivation. I actually like the summary of the importance of braces here in the blog post:Maybe the coding style contributed to this by allowing ifs without braces, but one can have incorrect indentation with braces too, so that doesn't seem terribly convincing to me.
Are you saying to remove the mention of goto fail
from the rationale? Do you want this sentence somewhere in particular?
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.
LGTM and thanks! I confirmed w/ the leads they're happy with this direction too so we're good to go. Thanks so much for getting it clearly written up!
proposals/p0623.md
Outdated
Some modern languages require braces, including Go, Rust, and Swift. Kotlin is | ||
an example which does not. Note some which require braces make parentheses | ||
optional. |
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.
Nah, I'm happy mentioning it, I just didn't want to overstate its importance. I've suggested a place where it could even be included in the disadvantages section, but that's optional given the comment in the rationale. Up to you.
Co-authored-by: Chandler Carruth <[email protected]>
…carbon-lang into proposal-require-braces
For error recovery, allow the braces around the controlled statement of an `if`, `while`, or similar to be omitted. Remove support for nested code blocks as this conflicts with struct literal syntax.
Require braces, never optional, particularly in control flow like `if`/`else`. Co-authored-by: Richard Smith <[email protected]> Co-authored-by: Chandler Carruth <[email protected]>
For error recovery, allow the braces around the controlled statement of an `if`, `while`, or similar to be omitted. Remove support for nested code blocks as this conflicts with struct literal syntax.
Require braces, never optional, particularly in control flow like
if
/else
.