Thursday, December 20, 2007

Why Python?

Why Python?

I am a programmer. I have been programming professionally for over 8 years, and I come by it by way of the usual route - I discovered computers (an Apple IIe), learned BASIC, then Pascal, then C. I completed high school "knowing" enough C to be dangerous. I also new a bit of forth and assembly. While in college I learned Shell, Java, JavaScript, Perl, Scheme (a favorite!) and some others. I took classes about programming languages.

Fast Forward a few more years and now I'm working full-time. I'm a Systems Administrator but I also write php, perl, and shell. One of my co-workers introduces me to Python over the course of a lunch one day. I respected this person's opinion quite a bit, but at the time didn't really give it much thought. Right before I was ready to leave the job and take a new one, I took a weekend and learned Python.

Like that.

In a weekend.


If you already know how to program (or think you do), you can pick up enough Python in a day or two to be productive. And productive is the key word, here - it's one of the biggest reasons why I continued with Python. I am more productive in Python than with any other language (insert caveats here). I like the syntax. I like the flow. I like the conciseness of the language. Statements that do what you think they do. No (or few, anyway) hidden surprises.

The Python Standard Library is practically the definition of Batteries Included. The Standard Library is solid and hugely comprehensive. I can write an XML-RPC client in 3 lines of code. I can write an XML-RPC server in under a dozen. I can change that server's behavior from one-at-a-time to threaded or forked with one more line. I can crack open an XML file, parse it into a DOM tree, and go rooting about in it in under 5 lines. Sure, the library has some warts, too, but over time many of those warts will be (are being!) removed.

The library helps you get real-world things done by making it easy for you to do them: internet protocols galore, interfacing with the filesystem, processing data. The language makes it easy to write my algorithm and structure the program in such a way that, in a year, I can come back to it and be confident that I'll be able to make changes and predict what those changes do. I can hear you saying now that "But that's just a matter of good programming, regardless of the language." and you'd be right. However, the language itself has a say in how you get there!

Python doesn't do everything, and what it does it doesn't always do perfectly. Speed is fast, but not C fast. Fast enough that the time saved in development often hugely outweighs the reduced out-and-out speed of the program.

Programming is really about solving problems, and in Python the tools to solve your problems are all part of the language. Take iteration, for example. Iteration is a base concept and the language provides iteration as a base feature. Python makes iteration easy. Python makes easy things scandalously easy and hard things easier.

Things in Python are easy to use. No pointers, no references, no hoop-jumping. I hate hoop-jumping. Hoop-jumping is all of that extra stuff that you have to do in order to do something. In C you have memory allocation, tracking, de-allocation. Pointers, arrays, arrays of arrays, and so on (and on and on!) and pretty soon you've got line noise. Segfaults. Buffer overruns.

Python gets out of my way and lets me solve the problem instead of concentrating on the syntax and hoop-jumpery. It lets me spend my precious brain cycles on solving the important stuff - the algorithm, the structure, etc... instead of spending so many ultimately wasted cycles on syntax.

I'm excited and a little frightened by what Python 3000 might bring. I've seen very wonderful changes from Python 1.5 through 2.6, and I hope for more in the future.

No comments: