3 ms·
So what you are describing is enums but way more complicated?
by beatbrot 6y ago
So what you are describing is enums but way more complicated?
- corylanou1 6y agoIn a way, yes. Go doesn't have the concept of enums, so this is as close as it gets.
- stouset 6y agoFurther demonstrating the point that simplicity in the language just winds up forcing complexity into your code.
- Groxx 6y agoAnd unsafe, since you can trivially make a `Genre(1138)` and that's correct, compile-able code. The same is true for a `Genre(0)`, which is easy to make by accident with just a `var genre Genre` declaration (that's a `Genre(0)` already). Or by ignoring an error return, like in `json.Unmarshal(data, &genre)` (that func returns an error, but that fact is invisible in text, and you are not required to assign or handle it. fun for code reviews!). You can also have a Genre-arg func like `func GenreToString(g Genre) string` and call it with `GenreToString(12345)` and that'll also compile. --- Go does not have anything even remotely like enums. It has a short-hand for auto-incrementing constants, nothing more. As if that were somehow the most valuable part of constants / enums.