Python vs. Perl

Thomas Wouters thomas at xs4all.net
Thu May 24 16:56:55 EDT 2001


On Tue, May 22, 2001 at 03:09:51PM -0700, Jonathan Gardner wrote:

[ Jonathan discovers Python is a great programming language ]

> What does Python have that makes it so great? Why should I spend time 
> to become intimate with it? I am looking for comments from people that 
> actually have used Perl or C/C++ extensively, and I am looking for comments 
> that go beyond the FAQ.

You've gotten quite a few responses alread, but I'd like to elaborate on a
point that Martijn only grazed: Python is incredibly easy to extend. The API
is fairly simple and very powerful (almost all 'builtin' modules and types
are implemented using that API, without 'special knowledge') and the Python
implementation itself is very clear and clean[*]. This makes Python (its C
code) not just fun to play with, it also makes it very portable.

What this means is that if you use Python, you aren't restricted to Python.
If you have an existing C library you want to use, no problem, either write
a small wrapper module, or use SWIG to auto-generate such a module. And
chances are there already are modules/wrappers for the library you want to
use ;) Python doesn't (yet) have such an extensive library as does Perl, but
in some areas it surpasses what I've found in Perl so far, like GUI support
and statistical/numerical stuff.

And if that isn't enough reason, there's more! Writing code in Python is
very easy, because you can write code almost as fast as you can type.
Especially if you already know how your program should look, because, say,
you're re-implementing something you already wrote in Perl or C. I've done
that myself, several times, and ended up with a much improved implementation
in the end. Most of the times it isn't necessary to translate it back into C
'for speed', especially if you want or need to use dicts (hashes.) Python's
dicts are just hard to beat.

Tim Peters (aka the timbot, watch for his postings in a cinema near you)
likes to explain how implementing an algorithm in Python rather than C or
more arcane (or should I say 'obscure', Tim ? :) languages, allows him to
find out why the algorithm sucks without wasting too much time on it. That
alone is a very good reason to use Python :)

And-if-you-miss-the-perl-oneliners--grow-up-or-check-the-FAQ-again-ly y'rs,
;-)

[*] Of course the code base could be cleaner, but it's a damned bit cleaner
than the cleanest bit of code I ever saw. And if you believe in source as
documentation, the Python source is the best reference manual for its own
API. You can see which functions are actually *used*, rather than documented
;)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list