News for hackers. Stuff that matters.
Re:Go Enums Still Suck by xienze on Thursday March 28, 2024 @07:29AM (#39849831)
There’s a history of this sort of faked annotation thing in Go. The most notable example being comments used to denote how a struct’s fields are mapped to/from JSON.
Re:Go Enums Still Suck by kelnos on Thursday March 28, 2024 @07:31AM (#39849848)
The struct field tags thing (which are not comments) is at least something built into the language, that other code can access via reflection. Not being able to do this for this use-case, and having to rely on comments that are preprocessed by a code generator, is just a shame.
Re:Go Enums Still Suck by zarldev on Thursday March 28, 2024 @08:14AM (#39850258)
Yeah extending the struct tags to iota definitions would have made things much better.
Re:Go Enums Still Suck by vsnf on Thursday March 28, 2024 @07:42AM (#39849947)
Maybe it's slightly better than total shit, but it's still pretty shit. Half the struct field tags aren't even typechecked, and will force you to go on hours long goose chases wondering why something isn't working only for you to realize eventually that 'someField string `db_orm_field_1:"0"' is actually supposed to be '"someField string `db_orm_field1:"0"'.
Re:Go Enums Still Suck by neonsunset on Thursday March 28, 2024 @10:44AM (#39852220)
Something like this just doesn't happen in C#. Neither in runtime reflection based ORMs nor in code generation based (micro)-ORMs (which, unlike Go, does not need extremely clunky manual scripting and "just works").