3 ms·
The important detail that has bogged down almost every union type discussion is "zero values". What would be the zero value of a union type? If you've written G
by melodyogonna 2y ago
The important detail that has bogged down almost every union type discussion is "zero values". What would be the zero value of a union type?
If you've written Go you know the entire language is built around zero values, disabling it for some types is not an option.
- the_gipsy 2y agoCouldn't it be just the first enum item? Zero values are somewhat arbitrary anyway.
- melodyogonna 2y agoWhy would it be just the first enum item? How do you even determine how the enum is ordered?
- aiono 2y agoI don't think this is a good idea. Because zero value changes when you reorder the fields.
- IshKebab 2y agoYou could use the first entry, or require an explicit annotation. That doesn't seem like a big issue.
- melodyogonna 2y agoYou would be wrong. Any use annotations complicates the language and compiler. As for first entry, this has been discussed many times without ever reaching any consensus, see - https://github.com/golang/go/issues/19412 https://github.com/golang/go/issues/19412