RFC -- Hygienic Macros in Python

Jason Orendorff jason at jorendorff.com
Wed Feb 6 15:10:00 EST 2002


Mike Carifio writes:
> Can someone fill in the newbies on this topic? Not all macro systems
> are just "blind text substitution". Scheme and LISP both have reasonable
> macro facilities which, when used judiciously, can actually enhance the
> comprehensibility of code (in my opinion, of course).

Well, one question is whether a feature honestly lends itself to
be "used judiciously" by the uninitiated coder.  Call it the
"judiciousness quotient", or JQ.  It's a pragmatic measure of how
easy a language feature is to use.

Consider overloading __call__().  I think the judiciousness quotient
for that is about 35%.  That is, 65% of the time it's used, it only
makes the code more mysterious.

eval() has a JQ of about 4%.

For new language features like list comprehensions and generators,
it's hard to tell.  My intuition says:

  list comprehensions: 50%
  generators: 75%
  macros: 20%

Also, when macros are used *in*judiciously, the pain is greater
than with, say, a confusing list comprehension.  Consulting the
source of a macro to figure out what it does is hard.  Or rather,
for any sufficiently interesting syntax, it's hard to write a
really clear macro.  (Of course, much depends on the syntax
provided for defining macros.)

## Jason Orendorff    http://www.jorendorff.com/





More information about the Python-list mailing list