Macro preprocessor.

Christian Tismer tismer at appliedbiometrics.com
Thu Aug 12 07:59:24 EDT 1999


Kaz Kylheku wrote:
[description of a cute macro processor skipped]

> Okay, enough. :) I'll probably get hate mail now about being off topic.

No hate mail, but some thoughts:

I can think of macro processors being useful for verbose, clumsy
languages. For sure it makes sense to use them for ASM, C(++),
and sendmail, for instance.

But why for Python?
Python is short, concise, readable, has a cute class system
and introspection.
Would any of the above be improved by introducing macroes, new
syntax, namespaces, and would this cost be justified?

There are a few cases where I admit that I generate scriptlets
on-the-fly using the formatting operator. I can also imagine
that macroes could be used to make debugging easier than with
conditionals in rare cases. Maybe I would like to splice
parameterized function bodies into a caller, maybe there is
a cleaner compromise somewhere between textual replacement
and the bytecodehacks approach.

But: Plain textual replacement is covered good enough by
the % operator, if this is needed. Macroes on the token
level are fine for languages with limited namespaces, no
inheritance features and so on. Python has these to a very
high extent, so what would macroes help what cannot be done
by classes and inheritance, which justifies another level
of indirection, new syntax, and all of that?

If I would introduce macroes into Python at all, then
probably on the parser level, in order to replace nodes
by equivalent constructs which are faster or would be
otherwise less readable. 

Conclusion: 
I consider it a virtue of a language if it is powerful
enough to go without macroes. Macroes are needed for
languages which have a lack of expressiveness, except for
Scheme, where macroes are part of the language with the goal
to use them to define language constructs. If introducing
macroes for Python at all, then they should use the existing
Python structures and namespaces, macro features should be 
bound to syntactic language elements and parts of expressions,
should not introduce another level of indirection but work 
at runtime. And I'd wish to see an example where a macrofied
source file is more readable than a plain one.

IMHO, this all does not apply for Python, and it the last 
language where I would want to use macroes. 

This is no complaint against your implementation which I think
is very useful for languages which really need it.

please-keep-the-good-work - ly y'rs - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     and we keep the good language :-)




More information about the Python-list mailing list