4 ms·
And 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 acc
by Groxx 6y ago
And 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.