3 ms·
We tried out struct-based enums like this for a while and they're definitely better than the vanilla version, but they still have the problem of "how do you ite
by mieubrisse 4y ago
We tried out struct-based enums like this for a while and they're definitely better than the vanilla version, but they still have the problem of "how do you iterate over all the values?" and "how do you create an enum value from a string?". We chanced upon https://github.com/dmarkham/enumer https://github.com/dmarkham/enumer a few months ago and have been very happy so far.
- mariusor 4y agoI think sometimes it's important to accept the shortcomings of the language we're using instead of chasing high overhead abstractions like the one presented in the OP and in the enumer package. I hate that go doesn't have enums, I hate that it doesn't have tagged structs, but if I spend my time trying to massage the language into simulacra of them, I'm losing time that I could spend writing productive code, or I muddle the waters for future developers that will have to deal with those abstractions in the future. Overall I think it's not worth it, outside of highly theoretical implementations like this, that can exist independent of code that actually does things.