On Sat, Apr 25, 2026 at 2:15 PM Denis Cheremisov
<
denis.ch...@gmail.com> wrote:
> What do you think about adding this to the Go grammar?
First, a minor technical note: in Go, packages do not form a
hierarchy. The directory structure is a tree, but to the compiler, foo
and foo/bar are completely independent packages. The term
"sub-package" implies an object-oriented relationship that Go's design
avoids.
Regarding namespace collisions: you noted that developers are forced
to manually invent local aliases. While this does require a one-time
explicit declaration per file, this is already the canonical, solved
answer to the problem. Go favors flat namespaces and explicit,
localized renaming over language-level hierarchical namespaces
(grpc.jwt.Foo). The time spent writing an import alias is microscopic
compared to the overall time spent building and maintaining a package;
it is typically a "write once and forget" action.
Furthermore, the cost of implementing this is high. Introducing a new
grouped import syntax would require changes to go/ast and go/parser,
effectively breaking gofmt, goimports, gopls, and virtually every
third-party static analysis tool written over the last 15+ years.
Given that a working solution already exists via named imports,
breaking the entire ecosystem's tooling to bypass a few seconds of
one-time import aliasing seems like optimizing in the wrong place. The
massive disruption IMO simply doesn't justify the minor convenience.
-j