5 ms·
See how it's used in the standard library io types, it makes for quite nice composition: https://go.googlesource.com/go/+/refs/heads/master/src/io/io.go#130 htt
by dgl 1y ago
See how it's used in the standard library io types, it makes for quite nice composition: https://go.googlesource.com/go/+/refs/heads/master/src/io/io.go#130 https://go.googlesource.com/go/+/refs/heads/master/src/io/io...
- mananaysiempre 1y agoI’m sympathetic to parts of the Go design philosophy, but the only thing that comes to mind looking at this is “damn, that’s some awkward (nominal-looking) syntax for (structural) intersection types”. (It also feels to me that this sort of anonymous embedding is materially different for interfaces vs structs, though I admit that from a type-theoretic perspective it’s not.)
- bilbo-b-baggins 1y agoYou can’t have ambiguous methods so the problem illustrated here fails at compile time for interfaces.
- whatevertrevor 1y agoUnioning interfaces like this does seem convenient for composition/mixin patterns, I'm not sure if extending it to structs in general seems worth the cost of potential footguns though, especially external libraries and such where you probably don't want to think about the full potential tree of embedding conflicts.