Earlier quoted context omitted.
You can think of macros as a compiler frontend. The compilation process is more or less: lexing -> parsing/macro expansion -> compilation of core language The macro expansion phase removes all uses of macros and produces a program in the core language (which has no macros). The idea is that a user can extend the language with new features. As long as a program that uses the new feature can be transformed into an equi…
> An often overlooked positive effect of macros is that the entire community can experiment with new language features. Sure, that sounds positive - but with enough macros, you can turn "your" version of the language into something completely unrecognizable to people that are only familiar with the "basic" version (or, otherwise said: congratulations, you've got yourself a DSL!), and I would say that's a rather negat…
Dart Macros and Focus
11–16 of 16 posts
Re: Dart Macros and Focus
#12Earlier quoted context omitted.
Generally meta features like macros are _far_ more useful to library authors that need to do some sort of "reflection" on your application code. Serialization libraries are frequently the largest beneficiary. In my ideal world I don't need to write macros or use language meta/reflection features while (only) writing code to solve business problems, but to get to that ideal often the libs you use do need reflection ca…
There's also the Lisp philosophy which emphasizes that you are your own libraries' author, too ! Third-party libraries can only help you with common business code - anything specific to your domain, or your business, you have to model yourself. Using macros is fundamentally not different than using classes or functions to create an environment[0] where expressing your business logic is straightforward, and invalid st…
Re: Dart Macros and Focus
#13Can someone ELI5 or point me to an idiots guide as to why macros are desirable? As a non professional programmer who work on small side projects I'm struggling to understand what benefit they bring.
Some modern languages (Haskell, Scala) overcome the lacking expressivity for library writers with higher-kinded types and principled support for ad-hoc polymorphism (e.g. typeclasses), thus reducing the need for meta-programming. Notably, Haskell and Scala have unusually principled support for metaprogramming.
As a heuristic, I would suggest that using metaprogramming for small or medium sized normal ("business") code is a sign that something maybe be suboptimal, and it might be worth considering a different approach (either to the choice of implementing business logic or the chosen programming language.)
Re: Dart Macros and Focus
#14Re: Dart Macros and Focus
#15Earlier quoted context omitted.
> An often overlooked positive effect of macros is that the entire community can experiment with new language features. Sure, that sounds positive - but with enough macros, you can turn "your" version of the language into something completely unrecognizable to people that are only familiar with the "basic" version (or, otherwise said: congratulations, you've got yourself a DSL!), and I would say that's a rather negat…
This is no different from having competing libraries for dates, regular expressions, html parsing etc.
Re: Dart Macros and Focus
#16Can someone ELI5 or point me to an idiots guide as to why macros are desirable? As a non professional programmer who work on small side projects I'm struggling to understand what benefit they bring.