Aw: Functional style programming in python: what will you talk about if you have an hour on this topic?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jul 16 08:46:42 CEST 2011


Rainer Grimm wrote:

> I think it's relatively difficult to get a feeling what a are the key
> points behind functional programming. So I think you should start
> explaining the concepts behind functional programming. A few ideas.
> - higher order functions
> - first class functions
> - currying
> - pure functions
> - list processing
> - lambda functions
> - recursion instead of iteration
> - pattern matching

Avoiding global state. Including singletons *wink*
Lazy data processing, including infinite data streams.
Decorators.
Iterators.
Using iterators as a form of pipelining.

Some of these might not count as strictly functional in the lambda calculus
sense, but they're closely related and less academic and more practical.


> And that should end with the three guys (map, filter and reduce ) as
> building blocks of functional programming. And that is a good point to
> introduce list comprehension. Because it's only syntactic sugar for map
> filter. But what kind of sugar. It's very impressive. Thats my typical way
> to introduce it in seminars.

If it were me, I'd probably take a less pure approach and concentrate on
concrete examples. As far as Python goes, the use of list comps/generator
expressions, iterators and decorators are the main functional idioms, not
so much map, filter and especially reduce, which only avoided being removed
from Python 3 by the narrowest margin.



-- 
Steven




More information about the Python-list mailing list