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/go: do not compile files larger than 1 MB #21562

Closed
dlsniper opened this issue Aug 22, 2017 · 7 comments
Closed

proposal: cmd/go: do not compile files larger than 1 MB #21562

dlsniper opened this issue Aug 22, 2017 · 7 comments

Comments

@dlsniper
Copy link
Contributor

Hi,

Before I start, I would like to state that I don't want to have this done in 1.10, 1.11 or 2.0 (whenever that would happen). However, I do wish to have a discussion around this. Maybe a different solution can be found so that both humans and editors (or other tools) can be better at this.

I'm writing this as I believe that it is a missing feature for Go, one which always left me with a bad feelign whenever I got near it.

Whenever I see code that longer than a couple of thousands of lines in a single file it just makes it terribly hard to follow / work with and understand what's happening.

Go's main feature for me, and I think/hope a lot of others, is readability. But that goes away when you have to keep reading such big sources.

To offer concrete examples:

Because of files like that, the documentation is often (caveat tables.go) bloated, see:

I understand that the examples are just code that's generated by tools but that doesn't mean that we must have a bad experience as programmers just because of the tools not being able to generate reasonable files. Equally, there is code out there (that I cannot link here) that is bigger than this.

Also, one can imagine code that wraps existing C libraries, which also tends to be rather big (see OpenGL for example).

The biggest downside of this proposal would be that generated code would need to suffer some improvements (as per example above). Equally, code that embeds resources would need to have a better definition and representation as to what this is (as seen above).

Thank you for your time and consideration.

@gopherbot gopherbot added this to the Proposal milestone Aug 22, 2017
@as
Copy link
Contributor

as commented Aug 22, 2017

Out of curiosity, on what order of magnitude are the resulting binaries for these huge sources?

@dlsniper
Copy link
Contributor Author

@as sorry, I don't have the numbers, nor do I think it would be relevant.

My interest with this proposal is to have the files readable, not work on a package scope nor on the binary size. This is of little concern to me as the Go compiler should be pretty good at removing the unused symbols, hopefully, and my normal deployments are on things that have enough disk space for binary sizes not to be of concern.

A different way to display documentation would be useful as well, see the examples, but that's probably better addressed in the godoc repository (and I don't have any good ideas on that for now).

@dsnet
Copy link
Member

dsnet commented Aug 22, 2017

While ridiculously large source files are annoying for humans, I believe the toolchain is the wrong place to address this. Other than that, I don't have any better suggestions other than some other tooling.

@mvdan
Copy link
Member

mvdan commented Aug 23, 2017

I share the intent, but not the solution. As @dsnet said, I don't think the toolchain is the right place for this.

For example, for a project of mine I need to quickly iterate on small changes made to a package's source code. Something I've considered is merging all files into one (like with x/tools/cmd/bundle) to speed up compilation. I don't see anything inherently wrong about that, yet the proposal would likely make it impossible.

I also don't understand the point about the godoc. The godoc page is loaded from all the files in a package, so it should not matter whether there are 10k lines in a single file or across five files.

This reminds me a bit about the linters that don't like code that is too long or too complex, such as https://github.com/fzipp/gocyclo. Have you thought about making a linter that would snap at any file larger than an amount of lines or megabytes?

It obviously wouldn't get the same community blessing as gofmt, but if it's included in popular tools and services, it could make an impact.

@griesemer
Copy link
Contributor

Go was designed with good readability in mind, but if somebody wants to write unreadable code there's no way to prevent that. Setting a max. source file limit is certainly not going to achieve that. What's way too big for one person, may be just fine for another one.

If anything, one might want to appeal to writers of APIs to organize them in a readable way. But some APIs are also generated from descriptions, so your mileage may vary.

At best, I see this is an appeal for good documentation and perhaps "reasonably" sized files. Maybe at some point we'll have some AI-driven tool that can judge the quality of a piece of code. But I don't think the compiler should have an artificial limit.

@rsc
Copy link
Contributor

rsc commented Aug 28, 2017

There is no single appropriate limit here. Tools need to be able to deal with large source files. This is not unique to Go. Past attempts to define size limits almost always turn out wrong. "640k should be enough for anyone" and so on.

@dlsniper
Copy link
Contributor Author

Agreed. Thanks for feedback and sorry for the delay. Do you think a discussion on golang-nuts for potentially a standalone linter would be helpful?

@golang golang locked and limited conversation to collaborators Aug 28, 2018
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

7 participants