57 ms·
> There's a reason languages like C# or Go don't have them, Go has a quasi macro system though (go generate) https://gradha.github.io/articles/2015/01/the-day
by throw_m239339 3y ago
> There's a reason languages like C# or Go don't have them,
Go has a quasi macro system though (go generate)
https://gradha.github.io/articles/2015/01/the-day-go-reinvented-macros.html https://gradha.github.io/articles/2015/01/the-day-go-reinven...
I like the macro systems in Crystal and Haxe (reifed macros)
https://haxe.org/manual/macro-reification-expression.html https://haxe.org/manual/macro-reification-expression.html
https://crystal-lang.org/reference/1.8/syntax_and_semantics/macros/index.html https://crystal-lang.org/reference/1.8/syntax_and_semantics/...
I think C would have benefited from such system at the AST level instead of text substitution.
Javascript is dynamic enough there is absolutely no need for Macros.
- ivxvm 3y ago> Javascript is dynamic enough there is absolutely no need for Macros. TypeScript macroses would be very useful for the same things codegenerators are useful: for example generating api client from swagger schema. Ofc you can do some trickery with metaprogramming, for example build and eval strings on fly and the result could be a dynamically generated function, but the point is: we want the process and the result to be typesafe and efficient, which is what is missing with hacky dynamic metaprogramming approaches.
- throw_m239339 3y agoA swagger schema looks like YAML with a finite set of types. I don't see why you'd need to use eval in that case when from one hand you already have the schema in a javascript object and the other hand a simple builder pattern would build your API directly from that schema. Absolutely no need for macros.
- eropple 3y agoGenerally speaking, because it would be very nice to have types without having to do offline code generation.