3 ms·
It's technically not macro as mentioned in the same page link: >C preprocessing expressions follow a different syntax and have different semantic rules than th
by teleforce 4y ago
It's technically not macro as mentioned in the same page link:
>C preprocessing expressions follow a different syntax and have different semantic rules than the C language. The C preprocessor is technically a different language. Mixins are in the same language.
D shows that it's possible to be a very powerful and potent programming language for DSL, etc, without all the conventional macro abuse and misuse.
If anyone asked me how come Python has becoming very popular nowadays, the answer will be it's one of the most intuitive and user friendly programming languages ever designed, and that's mainly due to the fact that it does not support macro [1].
[1]https://news.ycombinator.com/item?id=33431843 https://news.ycombinator.com/item?id=33431843
- int_19h 4y agoIt's not a C preprocessor macro. Those are a very specific and limited subset of macros, and that is the main reason why they're criticized. Broadly speaking, if something can generate parametrized chunks of AST on the go, it's a macro. Which is exactly what D mixins do. As for Python, it doesn't really need macros because everything is runtime. But if you need it, compile() and eval() are there, and they can be abused much worse than any macro facility ever could.
- teleforce 4y agoIt really depends on your definition of macro [1]. Modern programming languages like Scala, Julia, Nim, Rust etc are supporting hygienic macro. According to D authors Mixin is not macro because Mixin still looks like D language while supporting macro would meant the inclusion of macro (hygienic or not), and depending on the implementation, most often than not will render the language unrecognizable (become non intuitive). Again if someone is purposely writing a DSL in D for generating a new language's AST then that's perfectly fine. Essentially the output is another programming language because it is the intentional product of the exercises but the original programming language is still intuitive. I suppose you can have runtime macro like VBA but Python language designers refused to incorporate it due to issues as mentioned beforehand. [1]https://en.m.wikipedia.org/wiki/Macro_(computer_science) https://en.m.wikipedia.org/wiki/Macro_(computer_science)
- int_19h 4y agoSurely hygienic macros are a subset of macros, as follows from their name? I still don't see why D's mixins aren't hygienic macros. And the D documentation doesn't make that claim, either - it only highlights the difference with C preprocessor, not macros in general. OTOH I can't think of anything in VB6/VBA that resembles macros, runtime or otherwise?
- teleforce 4y agoSure hygienic macro belongs to macro but saner. Mixin is not macro according to D authors. If you dig into Walter's past posts, perhaps you can find better explanations there than mine. You can have macro in any runtime for example Ruby language, and that's the main reason for the maxim "Rails is not Ruby". That's also the reason Ruby is so powerful and to create a similar feat in Java will be close to impossible [2]. But at what cost? That's why Python now is much more popular even though Ruby is much more powerful. You can, however, create Rails clone in D language without all the macro nonsense [3]. [1]Ruby Macros Explained: https://codeburst.io/ruby-macros-18bb67e051c7 https://codeburst.io/ruby-macros-18bb67e051c7 [2]Stop Designing Languages. Write Libraries Instead: http://lbstanza.org/purpose_of_programming_languages.html http://lbstanza.org/purpose_of_programming_languages.html [3]Diamond CMS: https://github.com/DiamondMVC https://github.com/DiamondMVC