4 ms·
I have not touched zig, yet. But I hope they will use the duck typing approach how Golang does it, which makes it really nice to wrap APIs, mock APIs without ex
by weitzj 4y ago
I have not touched zig, yet. But I hope they will use the duck typing approach how Golang does it, which makes it really nice to wrap APIs, mock APIs without explicitly mentioning an interface
- weitzj 4y agoI guess it is the combination of duck typing + struct embedding + first class functions which let’s you adapt to an api or provide an api in a natural way without jumping through hoops
- dist1ll 4y agoGo'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.
- anonymoushn 4y agoI hope nothing is done similarly to golang, but you can do this by writing `anytype` which you may know as `auto`
- sidlls 4y agoI haven't touched zig, either, but I hope they don't go with structural typing. It leads to bloat: defining an interface explicitly to support unit testing, when stronger typing and appropriate use of fixtures and integration testing are much a much better approach.