Is there a way to change the closure of a python function?

Chris Angelico rosuav at gmail.com
Thu Sep 29 00:38:01 EDT 2016


On Thu, Sep 29, 2016 at 1:53 PM, Steve D'Aprano
<steve+python at pearwood.info> wrote:
> John Cook suggests that functional programming gets harder and harder to do
> right (both for the compiler and for the programmer) as you asymptotically
> approach 100% pure, and suggests the heuristic that (say) 85% pure is the
> sweet spot: functional in the small, object oriented in the large.
>
> http://www.johndcook.com/blog/2009/03/23/functional-in-the-small-oo-in-the-large/
>
>
> I agree. I find that applying functional techniques to individual methods
> makes my classes much better:
>
> - local variables are fine;
> - global variables are not;
> - global constants are okay;
> - mutating the state of the instance should be kept to the absolute minimum;
> - and only done from a few mutator methods, not from arbitrary methods;
> - attributes should *usually* be passed as arguments to methods, not
>   treated as part of the environment.

I would agree with you. "Functional programming" is not an alternative
to imperative or object-oriented programming; it's a style, it's a set
of rules, that make small functions infinitely easier to reason about,
test, and debug. My points about practicality basically boil down to
the same thing as you were saying - 100% pure is infinitely hard.

ChrisA



More information about the Python-list mailing list