Please explain why python rocks...

Gareth McCaughan Gareth.McCaughan at pobox.com
Wed Sep 6 19:47:07 EDT 2000


"nemir" wrote:

> I am a complete coding newbie,  looking for a first language to learn.
..
> I am not sure why I should choose any of those langauges over any of the 
> other languages I am considering.  Can you guys sell me on Python?
> 
> Bear in mind that I have no previous programming skills,  I don't know what 
> a tuple is.   I know what a variable is, and what an unsigned long is.... I 
> understand logical stuff like if-else statements,  loops and things....  
> Just don't know anything about how to make them work in a language.

Some good things about Python:

  - Python programs tend to be very easy to read and understand;
    simplicity and clarity are major design goals for the language.
    (Of course an evil programmer can write incomprehensible code
    in any language.)

    Once you've been programming for a while, you'll discover
    (and probably be shocked at) how easily you can forget how
    a piece of code you've written works. You'll come back to
    something you wrote 6 months, or 6 weeks, or 6 days, ago,
    and think "duh? what's going on here?". This will happen
    less in Python than in most other languages. This is a
    Very Good Thing.

    Perl and C++ are really terrible in this respect. Java and
    JavaScript are better, but Python is definitely ahead of
    them all.

  - Python comes with a bunch of useful "modules" for doing
    common tasks. You want to read or write HTML, or grovel
    through e-mail messages, or something like that? There's
    a good chance that someone has already done it.

  - Python involves very little gratuitous "scaffolding" of
    the sort you need in C++ and Java. A program that just
    prints "hello, world" and exits, in C++, looks like this:

        #include <iostream>
        int main() {
          cout << "hello, world\n";
          return 0;
        }

    whereas a program to do the same thing in Python looks
    like this:

        print "hello, world"

    Of course, for larger problems the "scaffolding" doesn't
    overwhelm the real code in quite the same way, but it's
    still a nuisance.

    (Java is similar to C++ in its level of pain. JavaScript
    and Perl are more like Python.)

  - Python frees you completely -- OK, *almost* completely --
    from one major class of headaches that will afflict you
    if you program in C++ (but not in Java, Perl or JavaScript):
    "memory management". I shan't try to explain this issue in
    detail, but trust me: this one causes a *lot* of pain in C++.

Here, in the interests of balance, are some arguments in other
directions.

  - For most tasks, programs written in Python will be slower
    than programs written in C++ or Java. (Especially C++.)
    Perl and JavaScript are roughly comparable, I think.

  - C++ and Java and Perl are trendier names at the moment
    than Python; they're more widely heard of and respected.

  - There isn't any book on Python that comes within a mile
    of "Programming Perl".

  - If you get used to writing in Python, you may find that
    other more complicated languages become unbearable to you;
    this may restrict your career. :-)

And a couple of other suggestions.

  - Once you've got the hang of Python, go straight out and
    learn some more languages. Don't tie yourself to a single
    way of thinking about programming.

    I wouldn't recommend any of the other languages you mention
    as next languages after Python; they're not different enough.
    Try ML, or Common Lisp, or Forth, or Prolog. Better still,
    all of them. You should learn C as well (whether or not you
    ever defile yourself with C++), and preferably at least one
    assembly language.

  - You mentioned a number of things you'd like to write. This
    is good. But don't just write code; read it, too. Find
    well-written code written by other people, and see how
    they do what they do.

    Incidentally, all the projects you mentioned would go as
    well in Python as in any of the other languages you
    mentioned. Python would probably be my language of choice
    for all of them.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construction



More information about the Python-list mailing list