-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: go 2 remove or make "package <ident>" declaration optional #27820
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
Comments
To add to the list of issues, there is that of external tests, e.g. The @matthewmueller what are you trying to solve for here? |
I haven't been around since Go's inception but it seems like To clarify the original post,
Fair point! Though I personally find
Further distilling the language to only the essentials. The initial motivation for writing this was I was renaming a folder with a ton of go files in it. As we all know, you have to rename all the I'm stepping out of my depths a bit here, but I'm pretty sure there's precedence for folder-based packaging in languages like ocaml. It seems like Go is more than halfway there with its best practices encouraging it. This would codify it. |
I don't know that. AFACT, There's no restriction on the package name that's related to name of directory holding that package. |
I will close this as a duplicate of #21479 |
Since the folder structure generally dictates what your package name will be, it might be nice to remove the extra
package <ident>
declaration. For backwards compatibility,package <ident>
could be optional.One issue is when you use hyphens like
foo-bar/foo-bar.go
haspackage foobar
, but I'd consider that generally bad practice anyway.Another consideration is tests, but in that case we could use the filename
*_test.go
to dictate the package name. There may also be issues withpackage main
, but could maybe default to the filenamemain.go
as defaulting topackage main
.I'm probably not be considering all the cases, but it does seem quite repetitive in general and it doesn't seem to add much, if anything it adds confusion when your package name isn't the same as your file directory. This is especially true when refactoring.
I'm curious to hear what you all think!
The text was updated successfully, but these errors were encountered: