3 ms·
> If your enum itself is not a string value, but you NEED a string representation, then it should just implement `Stringer`. I don't understand. Isn't this ex
by heleninboodler 6y ago
> If your enum itself is not a string value, but you NEED a string representation, then it should just implement `Stringer`.
I don't understand. Isn't this exactly what they did?
The only actual problem I see with this enum implementation is that the module-level value->string map is module public, which should definitely be fixed. Other than that, this looks like a bog-standard enum implementation with slightly odd internal naming conventions.
> I seriously have to add it to three different places?
Well, come on, now. The idiomatic example has two places to edit as well, and the third place here is for functionality the idiomatic example doesn't have (mapping back from string to value). You could always generate this map at runtime in an init() function but I suspect some would complain about that as well.