No macros in Python

Lulu of the Lotus-Eaters mertz at gnosis.cx
Sun Dec 15 19:50:16 EST 2002


Beni Cherniavsky <cben at techunix.technion.ac.il> wrote previously:
|IIRC nobody ever said that all macros are evil by definition.

Lulu of the Lotus-Eaters wrote:
> All macros are evil by definition :-).

Beni Cherniavsky <cben at techunix.technion.ac.il> wrote previously:
|My point was that sometimes spelling out the repetitive code patterns
|that macros can abstract over is more evil.

While my previous enunciation had tongue in cheek, I really do believe
that there is another word, besides 'macros', for "abstraction of
repetitive code patterns."  They are called 'functions'.  If I find
myself doing the same thing--or almost the same thing--repeatedly in
code, I write a function that does that collection of things.

Of course I realize that using functions can have a few extra issues.
You have to figure out what needs to get passed into the function, and
what needs to come back out of it.  But in general I would challenge
Cherniavsky, or anyone else, to present a case where anything could be
done significantly more easily in Python if macros were added.  I really
do not think there are any such situations.  Not if you consider the
various facilities for encapsulation already in Python (not just
functions, but also magic methods on classes, closures, HOFs, and so
on).

For all the raves I see about how wonderful Lisp macros are, it always
seems to amount to a slightly different way of spelling LOOP.  Yeah,
Python doesn't have an "do..until" construct, and maybe branching could
be done slightly differently.  But you can do everything these new
constructs might with no more than an extra line or two of code.  The
regularity gained by not letting people make their own monstrosity is
far more important than those couple lines.

Yours, Lulu...

--
    _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/
   _/_/    ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~  _/_/
  _/_/  The opinions expressed here must be those of my employer...   _/_/
 _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them!  _/_/





More information about the Python-list mailing list