What's better about Ruby than Python?
spam at yourself.pl
Thu Aug 21 10:58:11 CEST 2003
Chris Reedy wrote:
> I'm curious. Why do you feel such a need for macros? With metaclasses,
> etc., etc., what significant advantage would macros buy you? Do you have
> any examples where you think you could make a significantly crisper and
> easier to read and understand program with macros than without.
The first thing I would do with macros in Python is build an inline-facility
which allows certain functions being expanded whenever they are called.
This would hopefully increase speed at the sake of space efficiency.
Historically, macros have been used for building Prolog-like languages,
constrained-programming languages, lazy languages, very flexible object
oriented languages, etc. on top of Lisp.
In newer days, Design Patterns can be coded into the language via macros.
This enables you to program on a higher level of abstraction than with
classes. You can express your patterns more clearly and much shorter than
Indeed, the C++ community, which does not have macros, uses (some would say:
misuses) their template facility to do metaprogramming. They implement
design patterns, inline numerical code, etc. The resulting template code
is ugly. Compiler messages unreadable. Programming painful. But
developers feel it is worth to do because the abstractions they build are
powerful and run fast.
Having said that, I totally agree with earlier posters who said that macros
in the hand of bad programmers are catastophic. Where I don't agree is
that therefore the language should be more limited than necessary.
More information about the Python-list