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

gofmt: format grouped declarations in a pyramid instead of aligned on the equal signs #26391

Closed
nhooyr opened this issue Jul 15, 2018 · 3 comments

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Jul 15, 2018

See https://hisham.hm/2018/06/16/when-listing-repeated-things-make-pyramids/

E.g. instead of this format:

var (
    meow           = 3
    foobar34       = 4
    interestingl43 = "something"
    m              = 3
    ok             = true
)

Do:

var (
    m = 3
    ok = true
    meow = 3
    foobar34 = 4
    interestingl43 = "something"
)

For the benefits described in the article, namely it becomes very nice for git diffs because you only see the line that changed and its still super easy to read.

@meirf
Copy link
Contributor

meirf commented Jul 15, 2018

Using that blog’s own reasoning, we should not use this for gofmt.

From that blog:

Of course, all of this applies to lists where the entries are not semantically related: when listing color components one would always do “red, green, blue”, and not “green, blue, red”

But gofmt does not (and probably should not) know whether the variables are semantically related.

@mvdan
Copy link
Member

mvdan commented Jul 15, 2018

Usually, large or non-trivial changes to Go are done via proposals - see https://github.com/golang/proposal.

This proposal would mean two drastic changes to gofmt. First, the tool would now reorder declarations, which it has never done before. Second, it would no longer align them. The proposal needs to argue why the advantages are worth changing the formatting of so much existing code.

@nhooyr
Copy link
Contributor Author

nhooyr commented Jul 15, 2018

Fair enough.

@nhooyr nhooyr closed this as completed Jul 15, 2018
@golang golang locked and limited conversation to collaborators Jul 15, 2019
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

4 participants