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
New semicolon rule breaks 'if then{} newline else{}' #416
Labels
Comments
We're still in transition and much of the documentation hasn't been updated yet. (To avoid the inconsistencies you can run "hg update release" to get back to the old state.) We're aware of this specific problem, but it's not the gofmt formatting anyway, and all the ways you might imagine accommodating the alternate style complicate things in bad ways. You can convert your program using gofmt -w *.go. > I do not understand the reasons for it based > on the proposal given a few days ago for the new semicolon rules. > I notice that the Channels example in "Go For C++ Programers" is in the now > broken format: > if c.get { c.val = val; ch <- c } > else { val = c.val } Allowing this would require accepting if c.get { c.val = val; ch <- c } ; else { val = c.val } which would make the different pieces of the if different statements. That's pretty awkward. An alternative would be to peek ahead in the lexer and not insert ; before else, but that's an extra rule that must be implemented by the many tools and wouldn't have any benefit to programs written in the standard formatting. Complexity aside, there is a compelling benefit to not looking ahead past a newline to decide whether to insert a semicolon: it means that standard Go syntax can be used in newline-oriented contexts like interactive environments without any special cases. (Compare this to Python's interpreter, where an if statement must be followed by a blank line to get it to execute.) For all these reasons, I think the most likely outcome will be that the else behavior won't change. If you'd like to discuss this more, the mailing list is the right forum. Owner changed to r...@golang.org. Status changed to WontFix. |
Issue #430 has been merged into this issue. |
Issue #427 has been merged into this issue. |
This was referenced Dec 8, 2014
Closed
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by ray@hollett.demon.co.uk:
The text was updated successfully, but these errors were encountered: