
Ask HN: how to learn functional programming in Python - DeusExMachina
I have an odd question, to which I don't know if there is an answer: can I learn functional programming in Python?<p>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?<p>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...)<p>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.<p>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).<p>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.
======
probably
I was introduced to and learned functional programming through Python,
beginning with these series of docs:

<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.

------
jacquesm
Functional programming is a technique, and that technique is best expressed
using languages designed for the purpose.

Python 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.

------
spooneybarger
You can program in a functional style using python to an extent BUT... python
in many ways puts up roadblocks that make it a less than fulfilling thing to
do.

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 )

------
mnemonik
As others have pointed out, the best course for your goals (learning
functional programming and using GAE) is probably going to be Clojure (or
Scala).

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>

~~~
l0nwlf
lambda and map will be there. reduce will be moved to functools and filter
will be removed.

------
cydork
You should read following [http://stackoverflow.com/questions/1892324/why-
program-funct...](http://stackoverflow.com/questions/1892324/why-program-
functionally-in-python) [http://stackoverflow.com/questions/1017621/why-isnt-
python-v...](http://stackoverflow.com/questions/1017621/why-isnt-python-very-
good-for-functional-programming)

I still think if you are interested in learning functional programming choose
another language.

------
gruseom
If you want functional programming on the GAE, aren't Clojure and Scala more
obvious choices? Both were designed with the functional style in mind.

~~~
DeusExMachina
Sorry for the lack of knowledge, but they were not obvious to me. Is it
possible to use them on GAE? I thought, reading thei pages, that only Python
and Java could be used.

~~~
cydork
Check JVM-based Languages section in the following link
[http://groups.google.com/group/google-appengine-
java/web/wil...](http://groups.google.com/group/google-appengine-
java/web/will-it-play-in-app-engine)

------
python123
"The part of the answer on why I want to learn functional programming should
be clear to almost everyone here"

It isn't clear to me. Why don't you explain why you want to learn functional
programming?

~~~
DeusExMachina
Functional programming and all its pros and cons are a recurring theme here on
HN, AFAIK.

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.

