News for hackers. Stuff that matters.
Re:Go Enums Suck by llmblockchain on Friday March 01, 2024 @02:07PM (#39565509)
It's kind of strange to see them complain about enums and then promote a DSL-specific tool they made for generating enums.

At the same time, Go has generators built in and can generate enum tables, enum to strings, and other things they have shown. I am unsure why they didn't do it the "Go" way.

Re:Go Enums Suck by zarldev on Friday March 01, 2024 @03:34PM (#39566483)
DSL? The go way is to use go generate I would say and it can be used with go:generate, I would like to use the AST lib to parse go files to remove the need for any json and to be more like the cmd stringer tool.
Re:Go Enums Suck by llmblockchain on Friday March 01, 2024 @03:37PM (#39566509)
Yes. Your DSL is JSON in this case,

{ "enums": [ { "package": "cmd", "type": "operation", "values": [ "Escalated", "Archived", "Deleted", "Completed" ] } ] }

My point was the "Go" way to do this isn't parsing a custom format (like your JSON), but it's to use go generate.

Re:Go Enums Suck by zarldev on Friday March 01, 2024 @03:50PM (#39566644)
But all go generate does is run a binary like stringer? This can be used in go generate.
Re:Go Enums Suck by mariusor on Saturday March 02, 2024 @04:07AM (#39571188)
I'm not sure I understand exactly what you mean, but you can combine go:generate with go run so you can execute code from the current module/project that does what you want.

//go:generate go run ./internal/enumhelper -flag1 -flag2

Re:Go Enums Suck by mkesper on Friday March 01, 2024 @02:26PM (#39565750)
They complain that Go has no usable, type safe enum and then show a way to build them in Go.