Python vs. Lisp -- please explain

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Feb 19 07:03:15 EST 2006


The question about the speed is interesting. Generally the more dynamic
and flexible your language is, the slower are the programs it produces.
Lisp is almost unique in such matters (and in this regard it's maybe
better than CPython) because it allows the programmer to mix and blend
different levels of how much dynamism and how much optimized a part of
the program has to be. When you want to speed up a part of a Lisp
program (often developed starting from a slow but flexible code) you
start to use more specific functions, unboxed variables, simple arrays
of unboxed data, statically typed variables, etc. It's not easy, but if
you have some experience, often than one year, in that way you can
write programs only 20% or 50% slower than ones written in C, so for
most purposes they become fast enough. On the other hand you can
develop the program using an interactive shell and a dynamically typed
language, that speeds you a lot the prototyping, etc. You can have the
best of both things.
Python allows to mix various blends too (Psyco, Pyrex, ShedSkin, Weave,
SWIG, glues for Fortran and C/C++, etc), but in Lisp such blending
seems much more natural, finer grained, integrated in the language.
I think this isn't a limit of the language itself, because with enough
work two tools like Psyco and ShedSkin can become integrated in the
language itself (I think Psyco and SS are enough for 98% or purposes)
producing something not far from the "optimization flexibility" of
Lisp. Psyco compiles just in time some code, ShedSkin is more
aggressive, but if it becomes developed enough it can produce programs
fast as C/C++ ones with the same syntax of Python (some things aren't
supported). So then you can develop a program like in Lisp, where some
parts aren't optimized, some parts are compiled just in time, and other
critical parts are type inferenced and statically compiled for the max
speed (this requires to join ShedSkin with something like Swig, to
allow a natural, fully automatic and pythonic joining of .PYDs produced
by SS and CPython programs). PyPy can probably solve such problems in
similar ways or better, we'll see.

Bye,
bearophile




More information about the Python-list mailing list