Re:Fear of Macros
by current_call on Wednesday June 10, 2015 @07:39PM
(#9696404)
(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/m...
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
Brilliant. 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/m...
Macros do not necessarly transform code at compile-time. A late-binding interpretation is possible. See for example
http://programmers.stackexchange.com/a/274200/33157.
Even in an interpreter, they're expanded at "Load Time" as opposed to runtime.
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).