It's just unfortunate golang interfaces dont support fields. Only methods. Typescript fares better with its interface type
It's just unfortunate golang interfaces dont support fields. Only methods. Typescript fares better with its interface type
Why is that unfortunate? Usually when defining interfaces you care about the API surface without wanting to care about the internals of what will eventually implement that API. If you suddenly also spec fields with the interface, wouldn't be too easy to couple the internals to the API?
I can't say I've programmed in Go too much, so maybe I'm missing something very obvious.
I can't remember the specifics for why fields cannot be used within a Go interface but I do remember missing it a few times while writing Go code.
Struct field access is cheap, hopping through a dynamic dispatch table is less cheap.