3 ms·
What about sum types? During 4 years I've been programming Go professionally I missed sum types more times than I missed generics. Writing yet another interf
by ainar-g 8y ago
What about sum types? During 4 years I've been programming Go professionally I missed sum types more times than I missed generics. Writing yet another
interface SumType {
isSumType()
}
won't kill me, but it does get annoying.
- arianvanp 8y agofor sure. It would also be lovely to add sum types to Protobufs too, while we're at it. many message protocols are very neatly described with sum types in my opinion. Also, errors would be way more elegant as a sum type: instead of: err, a := x if err != nil { } we can do: switch a { Err(err) -> {}, Ok(a) -> {}, } and avoid null pointers :) and then "check" is literally just "bind/ try!, flatMap, =<<" or however your language du jour calls it :)
- mayoff 8y agoRegarding Protobufs, did you mean something other than `oneof`? https://developers.google.com/protocol-buffers/docs/proto#oneof https://developers.google.com/protocol-buffers/docs/proto#on...
- weberc2 8y agoAnnoying and the performance is terrible, since pretty much every instance ends up being an allocation, and allocations in Go are quite a lot more expensive than in other GC languages. Further, it doesn't quite have the same semantics--if you return one of these interfaces, your caller still doesn't know what all of the permutations they have to check for.