4 ms·
In my experience, Lisp-style macros are much less error-prone than the Ruby/Python-style meta-programming. I think it is probably because macros transform the s
by pg314 11y ago
In my experience, Lisp-style macros are much less error-prone than the Ruby/Python-style meta-programming. I think it is probably because macros transform the source code at compile-time while Python's meta-programming happens all at run-time. Errors are caught earlier and it is easier to build a mental model of how a macro accomplishes what it does (you can just expand and read the generated code).
Debugging or understanding Python code that uses meta-programming is usually no fun at all, but I have had much less problems understanding Common Lisp code that uses macros. It doesn't help that the meta-programming facilities of Python aren't very well designed (more like an accident of the implementation than a real design). If you're interested in a beautifully-designed approach to meta-programming (reflection and reification), 'The Art of the Meta-Object Protocol' (Kiczales et al.) is absolutely wonderful. I don't know enough about Ruby's meta-programming to say if it's better designed than Python's.
Of course both macros and meta-programming can be abused, like just about any language feature can (there's a series of mails that Guy Steele wrote to that effect as a reply to 'Macros make me mad': 'Classes make me mad', 'Procedures make me mad' some years back on the ll1-discuss mailing list).
- current_call 11y ago(there's a series of mails that Guy Steele wrote to that effect as a reply to 'Macros make me mad': 'Classes make me mad', 'Procedures make me mad' some years back on the ll1-discuss mailing list). I happen to have them bookmarked! http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02068.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m... http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02069.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m... http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02070.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m... http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02071.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
- davexunit 11y agoBrilliant. Guy Steele is very clever. Also, I like this list of macro writing rules in the last thread: http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02087.html http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
- ICWiener 11y agoMacros do not necessarly transform code at compile-time. A late-binding interpretation is possible. See for example http://programmers.stackexchange.com/a/274200/33157 http://programmers.stackexchange.com/a/274200/33157.