zlacker

[parent] [thread] 3 comments
1. bccdee+(OP)[view] [source] 2025-08-24 09:47:35
I would say more or less equivalent to textual macros. Unfortunately, as far as I can tell, the idiomatic way to write Go codegen (having skimmed some codegen repos and written some codegen tooling myself) is with the text/template package. Even battle-tested tools like protoc-gen-go are effectively built with printf statements rather than any sort of AST builder.

AST macros are complicated, yeah, and I agree that any half-decent macro system needs a convenient way to dump generated code and so forth. I'm not saying any macro system is better than codegen. But a decent macro system will give you hygenic tools to modify an AST, whereas codegen really forces you to hack something together. I'll grant that there's some worse-is-better charm to codegen, but I don't think that saves it from being ultimately worse.

replies(1): >>kragen+YQ1
2. kragen+YQ1[view] [source] 2025-08-25 03:41:04
>>bccdee+(OP)
A code generator is just a compiler; general arguments against code generation work equally well as arguments against using a compiler.

Writing a compiler is not "worse is better" and does not force you to hack something [fragile] together. Therefore, your argument is wrong.

replies(1): >>bccdee+8t6
◧◩
3. bccdee+8t6[view] [source] [discussion] 2025-08-26 15:12:33
>>kragen+YQ1
Empirically, I think you'll find that Go code generators are bad compilers. Go codegen isn't written with AST transformations and quasi-quote libraries. A macro system would be an opportunity for the Go compiler to take responsibility for the the tooling around metaprogramming; in the absence of that, we have a fragmented ecosystem where everyone is always reinventing a minimal, hacked-together version of the wheel so that they can get on with building the thing they actually need.

Frankly, an official Go codegen library would solve pretty much all my complaints, but the only difference between that and a macro system is compiler integration.

replies(1): >>kragen+na8
◧◩◪
4. kragen+na8[view] [source] [discussion] 2025-08-27 01:02:48
>>bccdee+8t6
Well, I do agree that bad compilers are bad, but I don't agree that a good compiler is basically a bunch of macros, or that emitting the code from the compiler backend with print statements correlates with a compiler being bad.
[go to top]