Re:Compile-time safety for enumerations in Go
by kiitos on Friday September 29, 2023 @09:53PM
(#37712161)
The point here is that, in Go, "what a Color type is" isn't something that can be enforced by the compiler. And more specifically, Go doesn't allow you to define reliable enums.
[ Parent
| on HN ]
Re:Compile-time safety for enumerations in Go
by gabereiser on Friday September 29, 2023 @10:41PM
(#37712362)
It is enforced by the compiler, what it doesn't do is guarantee it at runtime. I agree with you on the enums. Go doesn't have a reliable enum construct. But the argument that I, the library author, must validate and check against any possible type of "color" you, the program author, can come up with is just crazy talk. I'll provide a Color type, I'll even pre-define some colors for you, but if you send me a Color that's rainbow, I'll panic.
Re:Compile-time safety for enumerations in Go
by kiitos on Saturday September 30, 2023 @12:03AM
(#37712681)
It literally isn't enforced by the compiler, because I can compile code which is invalid.
Re:Compile-time safety for enumerations in Go
by gabereiser on Monday October 02, 2023 @08:58AM
(#37737486)
It’s not invalid because a string is a string. You didn’t invent a new type.