To us, here and now, it appears thus.

rants, ramblings and other things that make life worth living…

Python 2.5 – A Cursory Glance.

with 4 comments

Its long time since I wrote anything remotely techy. Though I’ve taken a small break from the outside world for personal reasons I’ve still been hacking around, the usual fun stuff you see. Now since Python 2.5 is out with a whole lot of new features I thought I should check it out . And well I’m impressed at a lot of work the guys have done and still I have a few peeves with it to. This is just a cursory glance and probably my opinions could change. So here is what I’ve gleaned so far from less than two days of hacking around. I will discuss the features that I found the most interesting.

Speed : This is one are where they have done lots of improvement. There is a perceptible difference in speed between the previous release and this release. I have moved a lot of maintenance scripts that I use to clean up my database and I managed to port them to python 2.5 without any problems. So a tip of the hat for the guys who’ve done the good work in improvements for speed. I have’nt checked out for compatibility so far, but if it doesn’t create new dependencies, I guess a lot of my mainstream projects would definitely get a power boost because they are basically frameworks other people use.

Co-Routines : Well, generators just got better with this version of python. They have been morphed into full blooded co-routines which already makes me think of the possibilites. For those who are new to these things, Co-Routines are functions on steriods. Normal functions have single point of entry and a single point of return (which may be dynamically decided of course). Co-Routines are cousins of functions which have can be entered at more than one point and can be left at multiple point and hence, they can be resumed. Though this looks like some form of primitive co-operative multitasking (which they are), They are also amazingly powerful programming constructs.

There are lots of situations where you could put this to use. Basically sometimes its easier to imagine your programs as moving from one state to another (exhaustive searches on graphs) or even better there are lots of occasions where you can actually consider the whole program to be a graph and the flow of control as traversing a graph in a particular order. Say a small MUD for example. Its a classic situation where co-routines can be put to good use. Another great place where you could use these is in finding patterns. In conjunction with partials (which I will discuss below) you can probably write pretty fast regular expression matchers. A boon for all those bioinformatics guys.

Partials : If you have any experience in functional programming, this shouldn’t be new to you at all. Partial Functions are functions which are built out of other functions with some arguments filled in with particular values. Kinda like C++’s default arguments, but a partial function always has a lesser number of arguments from the original function it has been constructed from. Let’s take an example so we can see them a bit more clearly.

consider the function add which takes in 2 arguments a and b so you define it as

add a b -> a + b

Now, consider another function inc, which is a partial function built from the original function..

inc = add 1 a

Of course this inc a is a partial application of the add function. There only one of the arguments of is defined and the other is passed down from the inc function. Now if the function could store a state (or is a co routine) and is partially applied in another function, then that gives us a powerful control structure. Imagine the possibilities…

Now that you have drooled over all that, I will give you the bad news. The syntax is absolutely clumsy. The syntax I used above is not the actual syntax, because the actual one is too verbose. This could probably be my Lisp/Haskell biases talking here, but in general I consider the syntax clumsy and not well thought out.  So thats a big dissapointment there.

Overall, at first glance, python 2.5 seems a good improvement with few dissapointments. Since I’m all itching to get something working with 2.5 time to get coding now..

Signing Off,
Vishnu Vyas (your favourite dungeon monkey)


Written by vishnuvyas

September 23, 2006 at 5:19 am

4 Responses

Subscribe to comments with RSS.

  1. I’ll never forgive myself for confusing partial application and currying (when I wrote that Lisp is Sin post) . Sigh.

    Sriram Krishnan

    September 28, 2006 at 6:08 pm

  2. Thats why I did uncurrying here (building a single argument function out multiple argument function rather than the other way around..)

    Vishnu Vyas

    September 28, 2006 at 11:49 pm

  3. Augustus

    Self done is well done…


    October 30, 2006 at 4:49 pm

  4. Gabriel

    When at Rome, do as the Romans do…


    October 31, 2006 at 5:34 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: