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

cmd/gofmt: leave short one-line function invocations on one line #4363

Closed
robpike opened this issue Nov 7, 2012 · 2 comments
Closed

cmd/gofmt: leave short one-line function invocations on one line #4363

robpike opened this issue Nov 7, 2012 · 2 comments
Milestone

Comments

@robpike
Copy link
Contributor

robpike commented Nov 7, 2012

Input:


package main

func main() {
    var a, b chan int
    go func() { for { a <- <-b } }()
}


Output:


package main

func main() {
    var a, b chan int
    go func() {
        for {
            a <- <-b
        }
    }()
}

The for loop seems to be the trigger to making this go statement multiline. One line
becomes five. It would be nice for concurrent example code like this to have simple,
short one-line closure invocations remain one line.
@cznic
Copy link
Contributor

cznic commented Nov 8, 2012

Comment 1:

Contracted to one line functions/function literals, like `func(x) { return expression }`
are just fine for me. But a loop construct should IMO stand out and deserves those three
lines, even for a one line "body". IOW, I prefer the status quo in this case.

@griesemer
Copy link
Contributor

Comment 2:

After some experimentation with this proposal (https://golang.org/cl/6846078/)
the Go team decided to leave things as they are: Nobody had convincing arguments in
favor, and there were significant doubts that it would increase readability. By
permitting different styles for 'for' and 'if' statements, code becomes less uniform and
likely less readable.

Status changed to WontFix.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants