Feeding Pythons

In these last few weeks, I’ve been working in a slew of programming languages. My OS course involves hacking around in the Linux kernel, so that’s in C. The projects in my AI course have been in Lisp, Java and the next one is in Prolog. At work, I mainly dabble in C++, but I’ve been helping with some continuous integration scripts in Perl and Python.

Out of all these languages, I think Lisp has permanently changed the way I think about programming. Unfortunately, it didn’t really click until after I submitted my project… After working a bit in Lisp and then going back to other imperative languages I found myself thinking of a Lisp-like solution and then realizing, “oh, this is was a lot easier in Lisp!” For example, trying to pass functions as parameters is very easy in Lisp since functions are first-class objects, but to do this in C one has defined a function pointer, which has very specific type definitions and some messy syntax, etc…

So, that led me to find this Google Tech Talk by Peter Seibel on “Practical Common Lisp.” This lecture further cleared up some of the concepts about Lisp (again, after I submitted my project, which I’m still waiting for the grade…) and that lead me to buy Peter’s book: Coders at Work, which is an amazing collection of interviews from great programmers. Anybody who is interested in

Cover of "Coders at Work"
Cover of Coders at Work

programming would find this book intriguing. After I finish it, I’ll put up a post specifically on that book.

Then I set out to make a small project in Lisp and ended up using Python 🙂 I wanted to integrate my Google Reader feeds with Emacs gnus and I found libgreader which pretty much handled all of the details with the still-unofficial Google Reader API. Inspired by reader2maildir, which does the same thing in Ruby, I set out to essentially port this to Python.

And I was able to download my feeds and read them in gnus, but since a lot of the feeds using embedded HTML or simply links to the main article (i.e. they don’t contain a summary) and would require me opening a web browser anyway, I figured the gnus approach wasn’t the best, for me.

But I learned a few things about programming in Python along the way. First of all, one has to be a little more specific while searching Google. Working with RSS Feeds, I realized it’s not adequate to search “python feed” due to the homograph “python.” Unappetizing images aside, I really like the interactive python interpreter. I didn’t really understand the point of using the interpreter directly and I thought it was useful only for toy programs, but it really helps in prototyping. Like Lisp’s REPL (read-veal-print-loop), interactive programming feels like precognitive debugging; it allows one to step through a debugger while the program is being written.

And while Python is not Lisp, it does have some functional style artifacts (much to the chagrin of its designer from what I understand). Python has a filter(function, sequence) function that:

returns a sequence consisting of those items from the sequence for which function(item) is true.

Combine this with a lambda expression, and I was able to write something like this:

filter(lambda x: x.unread != 0, reader.getSubscriptionList())

In this example, this line returns a list of feeds from Google Reader that contain unread items. So, I thought that was pretty cool 🙂 So while I would like to do some more stuff in Lisp, I was impressed on just how easy it was to get python running. That and with some Emacs-python integration, the development environment was very nice to work in.