3 ms·
Go's interfaces are an example of structural subtyping, not duck typing. The difference is that the structure a function expects is defined at compile time (i.e
by dist1ll 4y ago
Go's interfaces are an example of structural subtyping, not duck typing. The difference is that the structure a function expects is defined at compile time (i.e. in the function's signature) and not dependent of runtime usage of the passed in object.
- dontlaugh 4y agoIt's also quite frustrating in practice. It's often hard to understand that an error is actually lack of conformance to an interface (and why) and even worse, it's not uncommon to accidentally implement an interface you didn't intend to.