4 ms·
Macros are one of the widely touted superpowers of lisp. And yet in Clojure, which is the most widely used dialect in modern use, it is idiomatic to avoid macro
by BaculumMeumEst 2y ago
Macros are one of the widely touted superpowers of lisp. And yet in Clojure, which is the most widely used dialect in modern use, it is idiomatic to avoid macros as much as possible. None of the claimed advantages really hold up under scrutiny.
- rscho 2y ago> idiomatic to avoid macros as much as possible. Same in all lisps. The advantages of having macros vary on a case-by-case basis, but one thing is quite sure: the number of programmers collaborating on a project is inversely proportional to how much you should use macros. For a solo dev, especially when doing science-y stuff, they're invaluable.
- slaymaker1907 2y agoThat's only true of macros created for the purpose of reducing boilerplate code. However, the best macros actually reduce errors and improve code quality by enforcing invariants more than can be done without macros.
- bjoli 2y agoMany people use macros as a poor man's inliner, to generate code in a way that adds no benefits over a good compiler. You rarely actually need syntactic abstractions, but when you do you need macros.
- wtetzner 2y ago> it is idiomatic to avoid macros as much as possible. Of course, don't use a macro if you don't need one. But when you do hit a case where you need one, it's better than using/writing external tooling to solve the problem. > None of the claimed advantages really hold up under scrutiny. This doesn't follow.
- mst 2y agoMacros are an escape hatch. "Don't use a macro unless you need to" is good advice, but when you -do- need to, having macros around is lovely. Yes, you can achieve the same thing by typing out what would've been the expansion yourself, but in cases where macros are a good idea the expansion would've been sufficiently prone to mistakes when tweaking it that maintaining the macro is an improvement.