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: unwrap hard line-wrapped function parameter lists #24191

Closed
as opened this issue Mar 1, 2018 · 1 comment
Closed

cmd/gofmt: unwrap hard line-wrapped function parameter lists #24191

as opened this issue Mar 1, 2018 · 1 comment

Comments

@as
Copy link
Contributor

@as as commented Mar 1, 2018

What did you do?

Go format this code https://play.golang.org/p/eHh2k3LPzoz

What did you expect to see?

Exhibit 1: https://play.golang.org/p/M7ax5VTbxlY

What did you see instead?

Exhibit 2: https://play.golang.org/p/eUXlvJJHzZy

Summary

https://blog.golang.org/go-fmt-your-code says that Gofmt'd code is easier to write, read, maintain and is uncontroversial. With respect to the first example program, I disagree that gofmt achieves this.

The func A is a common artifact encountered in a codebase where one user has an editor with a pre-conceived notion that all characters are the same width and that line wrapping should be done with a hard newline at the source level. Gofmt solves this with a tab indent. I think it should instead remove the newline.

The func B is a less common but arguably more disgusting affair used upon disagreement with gofmt about the unsupported Allman brace style.

I think both of these should be addressed to make the points decorated in the blog post more accurate with the spirit of deterministic source code. There is currently easy way to de-uglyfy these functions without go/ast wizardly. Furthermore, both of these parameter lists appear this way in the godoc too. If the goal of gofmt is to make formatting deterministic and uncontroversial, I think it should be more opinionated about this.

Preemptive note: I don't think this should apply to parameter lists in general, it can be isolated to function parameters and the number of items in the list spanning a line in the source.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Mar 1, 2018

Sorry, gofmt is not soliciting change requests on its format at this time. Gofmt made a set of choices at one point, and everybody agrees to live with them, even if everybody might take issue with different individual choices. (as Rob says: https://www.youtube.com/watch?v=PAAkCSZUG1c&t=8m43s) For Go 2, @griesemer may trawl through the issue tracker for all old gofmt style request bugs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.