Repository navigation
Should Go libraries prioritize simplicity over extensibility? #6923
Replies: 1 comment
|
One useful test is whether the abstraction hides a decision that actually varies for a caller. For example, accepting an I'd start with concrete types and useful defaults, then add a small interface or option when a real caller needs the seam. Keep options independent where possible: five booleans can create 32 combinations that need documentation and tests. Public interfaces are especially hard to grow because adding a method can break external implementers. The Go code review guidance recommends defining interfaces where they are consumed and avoiding speculative interfaces. That isn't a rule against extensibility: plugin boundaries, transport selection, and an established standard interface are good reasons to expose it. The trade-off is whether the flexibility removes more caller complexity than it adds to the public contract. |
Uh oh!
There was an error while loading. Please reload this page.
I've noticed that some Go libraries introduce multiple layers of abstractions, configuration options, interfaces, and wrappers even when the underlying problem is relatively simple.
Go has always emphasized simplicity, readability, and explicit behavior. However, as projects grow, there's often pressure to make APIs more flexible and extensible.
This raises a few questions:
I'd be interested in hearing how maintainers approach this trade-off in real-world Go projects.
Where do you draw the line between useful extensibility and unnecessary complexity?
All reactions