New syntax for import scopes.

16 views
Skip to first unread message

Denis Cheremisov

unread,
8:15 AM (4 hours ago) 8:15 AM
to golang-nuts
Hi everyone, I'd like to discuss a common UX issue with large library ecosystems
(like gRPC, OTEL, or AWS SDK) where sub-packages often use overly generic names,
assuming they are the "center of the universe."

The Problem:
When using multiple sub-packages, we often get:

- manual.Resolver (from grpc/resolver/manual)
- jwt.Credentials (from grpc/credentials/jwt)

This leads to name collisions with other jwt or manual packages, forcing developers to
invent local aliases manually. Also, raw imports increases cognitive load during code reviews.

Proposed Solution:
Introduce a grouped import syntax that allows nesting sub-packages under a "parent" namespace:

    import grpc "google.golang.org/grpc" (
        .                // Embeds top-level grpc into the 'grpc' prefix
        jwt "credentials/jwt"
        manual "resolver/manual"
    )

Usage:
- grpc.ClientStream (from top-level)
- grpc.jwt.NewTokenFileCallCredentials()
- grpc.manual.Resolver

Key benefits:
- Scope isolation: No more collisions between grpc/jwt and other/jwt.
- Discoverability: IDEs can provide better autocompletion by grouping related sub-packages.
- Readability: The code clearly shows the origin of the sub-module without long, custom-prefixed  aliases like grpcjwt.
- This is a path grouping mechanism, not necessarily tied to Go modules, making it
 flexible for  both monorepos and fragmented ecosystems like OpenTelemetry.
 
What do you think about adding this to the Go grammar?
Reply all
Reply to author
Forward
0 new messages