Coder Social home page Coder Social logo

Comments (6)

karalabe avatar karalabe commented on May 27, 2024

E.g. Some live code from our repo that uses this style: https://github.com/ethereum/go-ethereum/blob/master/accounts/usbwallet/wallet.go#L443 Here I think any added new line would just make it harder to read.

from gofumpt.

karalabe avatar karalabe commented on May 27, 2024

Oh, one more instance where I think this is useful. After a inline-defined goroutine launch without any parameters:

go func() {
    // Do something
}()
noNeedForEmptyLineBeforeThis()

from gofumpt.

mvdan avatar mvdan commented on May 27, 2024

Thanks for filing this issue. I mostly agree with the sentiment, but I worry that this would be too agressive as a rule. When separating chunks of code, I don't think a comment is always enough. It can be enough if the code is simple and short, and if you're used to that style, but in reality not much Go code follows that style.

For example, I opened a random file from the Go standard library, and found multiple instances that don't follow this style, like https://golang.org/src/testing/testing.go#L767. In that case, you'd force the author to either move or add a comment, and I don't think the result would be more readable or more consistent.

One of the driving forces in these rules is to enforce what 95% of idiomatic Go code already follows. While you can argue that this would be something useful for some projects, I think it's not something that's widespread or a net readability win (see above).

from gofumpt.

mdlayher avatar mdlayher commented on May 27, 2024

This is extraordinarily subjective and I don't think there's any consensus that this approach is better or more readable.

I personally find it maddening to try to read a function that is 100 lines long with absolutely no blank lines to break up logical pieces. Whitespace can and should be used to group logical blocks of functionality.

from gofumpt.

karalabe avatar karalabe commented on May 27, 2024

This is extraordinarily subjective and I don't think there's any consensus that this approach is better or more readable.

Hence why I wrote "opinionated" and "wondering".

I personally find it maddening to try to read a function that is 100 lines long with absolutely no blank lines to break up logical pieces.

Apart from some extreme math heavy code, I don't think any program exists out there that is 100 lines long without a single for loop of if branch. If you do have those however, you already have empty lines on the closing braces.

I personally find it maddening to try to read a function that is 100 lines long with absolutely no blank lines comments to break up explain logical pieces.

from gofumpt.

mvdan avatar mvdan commented on May 27, 2024

While gofumpt is even more opinionated than gofmt, it tries to follow the already-present standards. I think this is too ambitious and controversial for the tool. And I definitely don't want to add flags :)

@karalabe if you can come up with a rule or heuristic that would keep most existing idiomatic Go code intact, I'm happy to consider it. Otherwise, this is unlikely to happen right now.

from gofumpt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.