Re:The Value in Go’s Simplicity
by riquito on Saturday November 16, 2019 @02:38PM
(#21554480)
Enums exist specifically to be compared with one of their possible values, how can you have a zero value problem?
[ Parent
| on HN ]
If the caller of your interface does not specify a value for your enum, they have implicitly specified the zero value. Whether that’s desirable behavior or not is up to you. For most clients, this behavior can be surprising if the zero value is a meaningful one (i.e. one that implies an intentional choice).
IME it’s useful to explicitly define the zero value’s meaning as “UNSPECIFIED”, to simplify the problem of trying to guess if the client intended to pass a zero value.
Re:The Value in Go’s Simplicity
by reificator on Saturday November 16, 2019 @06:51PM
(#21555691)
> Enums exist specifically to be compared with one of their possible values, how can you have a zero value problem?
Because there's not actually support for enums in go.
There's support for constant values, and automatically assigning sequential values to them. That happens to be useful for solving the same kinds of problems that enums solve, but they're not equivalent.