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

proposal: cmd/gofmt: treat one line if-statements as it does one line function definitions #44338

Closed
dandragona-dev opened this issue Feb 17, 2021 · 3 comments

Comments

@dandragona-dev
Copy link

Currently, gofmt will change:

func hi(){fmt.Println("Hi.")}
func bye(){
fmt.Println("Bye.")}

into:

func hi() { fmt.Println("Hi.") }
func bye() {
    fmt.Println("Bye.")
}

The tool could apply this to if-statements as well.

One line if-statements are controversial, and so my code reviewer and I believe that we should leave that choice to the user rather than requiring multi-line if-statements. We already leave this choice to the user in the case of function definitions, and so I was hoping that this wouldn't be much more work than that.

Our motivation for one line if-statements is that something like:

if choice == "" { choice = default }

is less distracting and arguably more readable than:

if choice == "" {
  choice = default
}

Thank you!

@gopherbot gopherbot added this to the Proposal milestone Feb 17, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Feb 17, 2021
@ianlancetaylor ianlancetaylor changed the title Proposal: Gofmt to treat one line if-statements as it does one line function definitions. proposal: cmd/gofmt: treat one line if-statements as it does one line function definitions Feb 17, 2021
@ianlancetaylor
Copy link
Contributor

CC @griesemer

@seankhliao
Copy link
Member

See also #4363 #27135 #33113

@rsc rsc moved this from Incoming to Declined in Proposals (old) Jul 28, 2021
@rsc
Copy link
Contributor

rsc commented Jul 28, 2021

This proposal is a duplicate of a previously discussed proposal, as noted above,
and there is no significant new information to justify reopening the discussion.
The issue has therefore been declined as a duplicate.
— rsc for the proposal review group

@rsc rsc closed this as completed Jul 28, 2021
@golang golang locked and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

5 participants