Updated: 4/1/05; 6:46:04 AM.
Feeding The Snake
Thoughts on Python, Science, Culture, and Life
        

Thursday, March 31, 2005

Functional Programming in Python

Functional programming is normally associated with the functions lambda, map, and filter, all functions that Guido says will be going in Python 3000. But in many ways Python functional programming is stronger than ever before.

I started programming in f77, where functions (subroutines) often run thousands of lines. When programming in modern languages I've learned to keep my program units down to perhaps 10-20 lines of code. The metric I've often used is what will fit on a single screen or a single (ack!) PowerPoint slide.

Almost as a game, I tried to see how much of my programs I could write as single line functions. The results have been striking in my code. My code is now much easier to understand and much easier to refactor in different ways.

A big part of the reason that I think that Python functional programming is still strong is what list comprehensions offer a way to express functional programming concepts in terse but still readable form.

I find that I'm writing more functions, but using each one more times, and by choosing the names appropriately, I can have the code comment itself.

Generators also allow terse program units to be compiled, although it's arguable whether they meet the same standard of readability set by list comprehensions. Maybe I simply haven't seen/written enough of them.


8:25:38 PM    comment []

Recent Music Acquisitions
Bought some really great albums from Emusic over the last few weeks. Emusic is doing a really good job hunting down new indie albums to add to their site, and I find I'm not getting bored with their selection.

Bought two from Antony and the Johnsons, the Self-Titled album, and "I am a bird now". Both are haunting and beautiful. The music is described as "genderqueer", but I'm a straight, married, boring middle-aged-white-guy, and I find that there's a great deal that I empathize with in Antony's music. Everyone has insecurities, but people who grow up with gender confusion have to confront those in a very direct way. Antony has learned to voice his hopes and fears very clearly and in a way that appeals to everyone.

Bought "Rejoicing in the Hands" by Devendra Banhart, who has a lot of vocal similarities to Antony, above. My interest in folk music has waned, but Banhart is much more melodic than most folk music, and his songs, particularly "The Body Breaks", which is available as a free download, are striking.

Why Cordalene isn't famous, or at least heard of, completely escapes me. Just bought "The Red EP" by them. "Isn't the Sun", which is available on the net as a free download, is just the best song I've heard in a long time, and certainly has the best bass line of any song I've ever heard. The band plays the type of garage/punk/pop that I'd love to hear more of, and I would be delighted if they got enough of a contract to put together a real album. The fact that they have a new web site is a good sign, so fingers crossed.

When the hell is Say Hi To Your Mom going to put out a new album??
6:16:59 AM    comment []


© Copyright 2005 Rick Muller.
 
March 2005
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Feb   Apr


Click here to visit the Radio UserLand website.

Subscribe to "Feeding The Snake" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.