5 ms·
That's idiomatic go. See https://go.dev/blog/generate https://go.dev/blog/generate and '//go:generate stringer -type=Pill' See also '//go:embed', which also tu
by TheDong 3y ago
That's idiomatic go. See https://go.dev/blog/generate https://go.dev/blog/generate and '//go:generate stringer -type=Pill'
See also '//go:embed', which also turns a variable into a magic type via an ad-hoc comment-only DSL.
In go, it is idiomatic to say "macros slow down compilation and often require a second pass, go compilation is fast, macros are bad", and then also to have an extra "make sure go generate is up to date" CI step which parses your go codebase 10 more times, forks dozens of processes, and isn't type-safe since of course it's not it's literally a comment you can typo "//gog:enerate" and no one will notice.
- grey-area 3y agoWorth noting that most go codebases don't contain magic comments like this. I've certainly never used them and agree they are horrible in every way.
- joneholland 3y agoI frequently tell people that Go is my least favorite language for reasons like this and the response is often some form of the no true Scotsman fallacy.