|
|
|
|
|
by randomdata
1491 days ago
|
|
> It doesn't. It does. By definition, an enum is simply a set of named values, which you code example provides, and is behaviourally the same as C. > it does not at any point hint or imply the set could be in any way closed. While true, that is a feature of sum types, which I already indicated Go does not have. This is slightly different to enums. |
|
No.
> By definition, an enum is simply a set of named values
That is not the definition of "an enum", no. "an enum" does not imply a complete absence of any sort of type safety.
"a C-style enum" might, but that is not the distinguishing characteristic of C-style enums, the lying is, otherwise literally every language which has constants has C-style enums, including every language with sum types.
> and is behaviourally the same as C.
Except for all the ways in which C enums mislead users into assuming any sort of non-existent type-safety guarantees.
There is a critical distinction between "C-style enum", aka a misleading pile of garbage, and "just a bunch of constants". The latter is what Go provides.
> While true, that is a feature of sum types
That is not correct. For instance Java enums are not sum types, but are a type-safe, closed, set of values.