Wednesday, December 16, 2009

Functional Programming In Python

At this month's PyGTA meeting we attempted to write a trivial application in Python using functional programming concepts. First, lets be clear: Python is not a natural language for functional programming. For one thing, the Python interpreter does not support the parallelism that a proper functional programming language will offer. However, it is possible to write in a functional style in Python, just don't expect much in return for your efforts.

The real difficulty was not Python itself but the group's lack of experience with functional programming. When you are used to using variables everywhere, it is actually quite difficult to write code that uses none. We commonly use varibales to save state and since functional programming is stateless, variables are a big no-no. In the end only Mike Fletcher got something that worked using functional programming techniques, but it still used a couple state variables, and so the program was not completely correct.

So what was learned from the experience? Functional programming is a lot harder than anyone thought. Next time someone waxes about how great a paradigm functional programming is, ask him to you show a real application he has written. If he hesitates, you can safely ignore everything he says.

No comments:

Post a Comment