4 ms·
> Except you can't really do this with interfaces Apparently they decided that it would be too confusing to have variant types alongside interfaces for some re
by kubb 5y ago
> Except you can't really do this with interfaces
Apparently they decided that it would be too confusing to have variant types alongside interfaces for some reason, and they claim that interfaces handle a lot of the use cases of variants:
https://go.dev/doc/faq#variant_types https://go.dev/doc/faq#variant_types
- autarch 5y agoYeah, "for some reason" is a good summary of many Go decisions. Rust has both (traits are somewhat like interfaces) and I don't feel like it's too painful, though using the trait type in function signatures is a lot more involved than in Go, and I still don't fully understand all the nuances. But the complexity isn't because of any overlap between traits and sum types.
- throwaway894345 5y agoRust trait objects are surprisingly painful. I've reached for them a lot where I would normally use Go interfaces, but ended up avoiding them. I suspect this has more to do with Rust's memory management model--having sum types and interfaces would almost certainly work out perfectly in Go.