osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Style Q: Instance variables defined outside of __init__


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> What they came up with is that its really hard to do useful work for 
> large applications with 100% pure functional programming styles. As you 
> add functional techniques to your code, you find your code quality 
> increasing. Things like pure functions with no hidden state and no side 
> effects can have a massive positive effect on code quality -- up to a 
> point.
>
> As you approach closer and closer to 100% pure functional code, you get 
> fewer improvements and your code gets harder to write and maintain.

Right. I hope no-one advocates a *purely* functional approach to any
program that needs to do work on anything external.

Functional programming is a paradigm that is an essential tool to
*minimise* the side-effects of code, with a corresponding increase in
the testability and therefore the confidence one can place in that code.

Any program which needs to interact with systems outside itself ? which
is to say, any program which performs useful work, ultimately ? must
have side effects. So it's absurd to advocate removing *all* side
effects.

So, those who sneer that Python isn't purely functional are, in my view,
paying Python a compliment: that it doesn't get in the way of doing
useful work on things people care about getting done. Python supports a
highly functional style, while not going IMO too far down the road of
purity at the expense of usefulness.

-- 
 \        ?The reason we come up with new versions is not to fix bugs. |
  `\                     It's absolutely not.? ?Bill Gates, 1995-10-23 |
_o__)                                                                  |
Ben Finney