Why should I switch to Python?

Glyph Lefkowitz glyph at twistedmatrix.com
Wed May 10 12:59:39 EDT 2000


Russell Turpin <noone at do.not.use> writes:

> In Perl, someone once observed, there are seven good 
> ways to do anything. 

I think that should be amended to, "In Perl, there are seven
apparently good but subtly wrong ways to do anything.".

> For this reason, I prefer Python.

Just to add my drop of gasoline to the fire ;)

Poorly written python code will get you a code savings of 30% from
other languages (less for perl, obviously); just for leaving out the
braces, the variable declarations, and the punctuation, and it will
probably repeat itself a little less.  (argument-passing symantics are
so wacky in perl I have often found myself copying and pasting whole
blocks of code rather than writing a subroutine and tracking down
where I forgot to use a 'my').

*Well* written python code, that uses all the twists and turns and odd
little corners and cool features of the language, will probably end up
being (no kidding) 80% shorter than the equivalent (let's say) java
program.  I am willing to bet that it would be about 40% shorter than
the equivalent Perl script; but more importantly, it will be better
designed.  The savings are *especially* apparent as the program
scales, as python has a very simple way of reusing code: just import
another .py file!  "module" declarations, header files ... they all go
away.

There are more terse ways to express everything in perl, but perl's
syntax is dense enough that sometimes it's easier to just "do it the
hard way". (especially if one of your goals is maintainability).  This
requires conscious effort; whereas in python, it's all natural.

Python has opened up paradigms about programming to me that were
previously cut off.  Things that, in other languages, are either
simply impossible (__getattr__ and __setattr__ are my friends) or
merely fragile (python is the only language where I have seriously
considered using a hash of function pointers).  I never understood why
LISP was a good idea until I started playing with python: now much of
the wisdom of the "old guard" of programming makes sense to me, as
well as many newfangled ideas about testing, "extreme programming",
etcetera.  It is so easy for me to understand that when I work on a
hard problem in java, I implement the algorythm in Python first,
because things are becoming easier for me to implement in python than
to describe in english.

This is all hearsay, of course, but I would be willing to place a
gentleman's bet that if you use python for a moderately large project,
you will find it harder and harder to go back to perl afterwards.

In other languages, I begin with a concept in english, and then
obfuscate the concept with code to arrive at an implementation.  In
python, I begin with a concept in python, and the implementation
becomes implicit.  All that is necessary is for me to improve it.

guido-is-our-god-and-the-timbot-his-prophet-<wink>-ly y'rs,

-- 
                  __________________________________________
                 |    ______      __   __  _____  _     _   |
                 |   |  ____ |      \_/   |_____] |_____|   |
                 |   |_____| |_____  |    |       |     |   |
                 |   @ t w i s t e d m a t r i x  . c o m   |
                 |   http://www.twistedmatrix.com/~glyph/   |
                 `__________________________________________'




More information about the Python-list mailing list