News for hackers. Stuff that matters.
Re:Safer Enums in Go by Strum355 on Saturday May 14, 2022 @10:30AM (#31378263)
Not going to link it anywhere? I have some doubts given how widely it wouldve been shared if the claim is actually true, and your not linking of an example kinda just furthers that
Re:Safer Enums in Go by Splizard on Saturday May 14, 2022 @10:46AM (#31378443)
Re:Safer Enums in Go by esprehn on Saturday May 14, 2022 @11:11AM (#31378714)
That code appears to be using reflection to build up runtime tables?

https://github.com/qlova/tech/blob/c6379c9c32e5b7b2973bc02ba...

https://github.com/qlova/tech/blob/c6379c9c32e5b7b2973bc02ba...

That's a big difference from other languages where this is all handled at compile time.

Re:Safer Enums in Go by suremarc on Saturday May 14, 2022 @11:39AM (#31379032)
This is cool, but it doesn't seem like Switch is implemented for Int, and the use of runtime reflection limits the contexts in which this implementation can be used, compared to a language construct that gets compiled into efficient machine code. I wouldn't want this to be endemic in my codebase or my dependencies.
Re:Safer Enums in Go by Splizard on Saturday May 14, 2022 @11:55AM (#31379198)
Enum supports an exhaustive Switch as well, here's an example based on the blog post: https://go.dev/play/p/Ef78vLyw33g
Re:Safer Enums in Go by arriu on Saturday May 14, 2022 @12:04PM (#31379296)
Is it just me or is the syntax on these worse than the issues it’s solving?
Re:Safer Enums in Go by masklinn on Sunday May 15, 2022 @06:13AM (#31386558)
It's not you, this is a worse version of std::variant, which isn't exactly great in the first place.