embrace the heresy [01/04/2007 06:13:40]
Python, ladies and gentlemen, is not a functional programming language. Functions are first class objects. There's a lambda keyword. And it has two beautiful functional constructs in the form of generators and list comprehensions. But if you try to write your whole program in a functional style, you always seem to be going against the grain of the language.
In a functional language, everything is an expression, meaning everything returns a value. In python, some things return values, but many things don't. The things that don't return a value are called statements. For example, the if construct is a statement. The while and for loops are statements. And so on.
Things are getting better. Ever since list comprehensions were introduced, we've been able to use for in an expression, and you could use a limited form of if as an expression inside the list comprehension: [x for x in xs if x > 2]. And now, as of python 2.5, you can finally use if as an expression anywhere: (x = 1 if True else 2).
But if you like this style, and you start trying to use it everywhere, you run into problems. The most common example is wanting to create an anonymous function on the fly (a lambda) but needing to use a statement - perhaps an assignment (because python doesn't have a let construct). At that point, you have to go to another part of the code and define a function.
There's no technical reason why you can't do these things. The python virtual machine would certainly allow it. The problem is that the syntax is deliberately designed to prevent using a functional style. For example, Ruby and Smalltalk have a very nice syntax for anonymous blocks - like lambda done right. For a while it looked like python might get these too, but instead we got the with block.
The general sentiment seems to be that some functional features are nice, but only in small doses inside the standard object-oriented/imperative paradigm.
This is one reason people leave for ruby. Ruby isn't quite a functional language either, but it has many more features. But I have two problems with ruby: first, with the exception of Rails, the libraries aren't all that spectacular, and second... Well, ruby just isn't that much better than python. If I'm going to relearn everything, why would I bother with ruby? Why not just jump straight to lisp? Well, because the lisp libraries are even worse off.
No, what I want is functional python.
And that, my friends, is heresy.
But: so what?
There could be.... advantages.
The great marketing genius Seth Godin is always talking about how you've got to be remarkable if you want to get attention. My little web framework is not terribly remarkable. Why? Because it's just like all the others. Why? Because I put up with the things I didn't like about python rather than doing what I really wanted. I figured nobody would ever use it if I made it look like lisp. When Rails and Django came along, I figured I might as well throw in the towel.
But what if I made heresy the selling point of my little web framework? Not because people want to be heretics, but because I can't be the only one out there that loves python but wants something more. It might be a small community, and a lot of people would just plain hate it, but the people that stayed would very likely fall in love with it.
So, I think it's finally time to settle on a name for this dang framework. Something that embraces the heresy of functional python. A symbol even.
Ladies and gentlemen, I have found such a symbol. Prepare yourself, for I give you... The Scarlet Lambda!

