4 ms·
I see this suggested all the time as though it’s supposed to be a replacement. It isn’t sufficient, it’s a poor emulation of what enums can be used for and does
by physicsguy 2y ago
I see this suggested all the time as though it’s supposed to be a replacement. It isn’t sufficient, it’s a poor emulation of what enums can be used for and doesn’t offer the same protections, since Status can be set to any integer value without casting or any knowledge that it’s broken.
In your suggested method it doesn’t even catch that case and provide an error if the value isn’t in the range.
- powerhugs 2y agoIt seems like none of the other comments here use or are even aware of `go generate`. Go has excellent code generation features [1]. I think parent should be using `stringer` [2] instead. 1: https://go.dev/blog/generate https://go.dev/blog/generate 2: https://pkg.go.dev/golang.org/x/tools/cmd/stringer https://pkg.go.dev/golang.org/x/tools/cmd/stringer
- physicsguy 2y agoI'm well aware of Stringer but I don't again think it's a good replacement of having enums built in!
- powerhugs 2y ago> I don't again think it's a good replacement of having enums built in! I didn't say anything along those lines, in fact I was commenting generally about this issue that you guys and the other commenters mentioned. I was just suggesting a solution to the the problem stated.
- fullstackchris 2y ago"We don't want a solution! We want to complain about what we are used to and dont have!"