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

Open
dandragona-dev opened this issue Feb 17, 2021 · 2 comments
Labels
Projects
Milestone

Comments

@dandragona-dev
Copy link

@dandragona-dev dandragona-dev commented Feb 17, 2021

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

@ianlancetaylor ianlancetaylor commented Feb 17, 2021

@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Feb 17, 2021

See also #4363 #27135 #33113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants