News for hackers. Stuff that matters.
Re:Leveraging the Go Type System by beatbrot on Tuesday February 09, 2021 @11:34AM (#26079443)
So what you are describing is enums but way more complicated?
Re:Leveraging the Go Type System by Groxx on Tuesday February 09, 2021 @02:42PM (#26081649)
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.

Re:Leveraging the Go Type System by corylanou1 on Tuesday February 09, 2021 @11:39AM (#26079517)
In a way, yes. Go doesn't have the concept of enums, so this is as close as it gets.
Re:Leveraging the Go Type System by stouset on Tuesday February 09, 2021 @01:09PM (#26080674)
Further demonstrating the point that simplicity in the language just winds up forcing complexity into your code.