What's better about Ruby than Python?

Alexander Schmolck a.schmolck at gmx.net
Mon Aug 18 19:08:59 EDT 2003


Roy Smith <roy at panix.com> writes:

> Alex Martelli <aleaxit at yahoo.com> wrote:
> > I do hope that Python never gets such a powerful macro system
> 
> I'm with Alex on this.  Macros suck.  What you usually end up with is 
> essentially two different languages, with different syntaxes, and which 
> don't interract very well.  If nothing else, this really screws up emacs 
> auto-indenting :-(
> 
> One of the few things I like about C++ is that between const, templates, 
> and inline, the need for the macro preprocessor has been almost 
> eliminated. 

Yeah, which is exactly why people are now writing books on and holding
conferences about some idiocy called template metaprogramming (which involves
extremely painfully building a modest subset of common and trivially defined
functionality offered by CL macros, see
http://www.prakinf.tu-ilmenau.de/~czarn/meta/metalisp.cpp).

> I don't even want to talk about the various systems which make use of 
> things like m4.
> 
> Why do you need macros?  There's a few things people do with them:
> 
> 1) Define constants.  In Python, you just define symbols in your module, 
> and get over the fact that there really is no such thing as a constant 
> in Python.
> 
> 2) Define efficient pseudo-functions.  In Python, you just define a 
> function (or method) and get over the fact that it's not as efficient as 
> a macro.  If I cared about microseconds, I wouldn't be writing in Python.
> 
> 3) File inclusion.  In Python, you don't include files, you import 
> modules.
> 
> 4) Conditional compilation.  In Python, you can conditionally define 
> anything you want at import time.

I think you should maybe do some reading about real macros first (like 'on
lisp', freely available on www.paulgraham.com), you wouldn't really use macros
for any of the above [1] (other than the ultra-primitive macros in
ultra-primitive languages like C and C++).

 
> 5) Inventing your own language constructs.  In Python, you just don't do 
> this.

Tautologically so, yes.


'as

[1] That is the prexisting facilities you use to do those things might
    internally be built with macros, but that's none of your concern. You
    wouldn't define your own macros for any of the above in a proper
    programming language. 2) is a possible exception, but then you wouldn't
    just do something primitive that amounts to just inlining the code (for
    which there is an inline directive).




More information about the Python-list mailing list