Ask HN: how to learn functional programming in Python
First, let me answer to the obvious question that is coming to your mind: why? The part of the answer on why I want to learn functional programming should be clear to almost everyone here, so the real question is: why Python?
I know that there are a lot of better functional languages out there. The reason I chose Python is that for for my next project I decided to use Google App Engine, because I think that it is a very cost/time/resource effective way to implement what I want. And Google App Engine uses Python (or Java...)
So, to kill two birds with one stone, I'd like to learn functional programming directly in Python, so that I would be able to learn it as I go implementing my app. I already understand what functional programming is and how to program in a functional style, but going only with what I know I will surely miss something.
Everything I find for Python is object oriented (and I can understand why), but I really would like not to have to learn it in one language and then switch to Python (but I know this could be a better way).
Is this possible? Do you recommend not doing it this way? Can you recommend books/resources/anything? Everything is really appreciated. Thank you very much.
12 comments
[ 3.2 ms ] story [ 31.9 ms ] threadPython has enough elements of functional programming languages that it should be relatively easily done, but it won't be 'the real deal'.
The interesting thing is that this exercise will probably make you a better python programmer, mutable state, side effects and parameter modification are 'bad' traits anyway, and getting functions to always return the same result dependent solely on the input parameters is 'good'.
This may be of some help:
http://norvig.com/python-lisp.html
It's intended for lisp programmers to make it to python, but I think plenty of the stuff in there should apply to your situation.
I would say you could become familiar with functional programming in python but you can't experience the full depth of functional programming, for that given your general goals... I would suggest looking at clojure ( runs on jvm and gae )
Python has taken some idioms from functional languages, but if you try to really code in the functional paradigm you will but heads with the language. Statements and expressions are very sharply divided. Lexical scoping is broken. Lambdas are one line only.
Guido even suggested removing filter, reduce, lambda, and map from Python 3k[1]. If that isn't a signal that the functional paradigm won't be nurtured, I don't know what is.
[1] http://www.artima.com/weblogs/viewpost.jsp?thread=98196
http://www.ibm.com/developerworks/library/l-prog.html
http://docs.python.org/dev/howto/functional.html
I would say I program primarily, though not strictly, in a functional style in Python, Lisp, and R. For my applications it's more for the purpose of a modularity rather than concurrency-critical issues, so Python's functional programming limitations aren't noticeable (don't know in your case). There is a 'functional' module available for Python which extends on map, filter, and reduce, and lambda's single-epxression limitation does not necessarily make it functional-hostile.
It isn't clear to me. Why don't you explain why you want to learn functional programming?
I did not want to mean that everybody here uses it or advocates it, but I think almost everybody knows what leads a developer to move to functional programming.
I still think if you are interested in learning functional programming choose another language.