suggestions for functional style (singleton pattern?)

Michael Torrie torriem at gmail.com
Sun Mar 1 00:14:11 EST 2015


On 02/28/2015 09:11 PM, yves at zioup.com wrote:
> On 2015-02-28 19:19, Michael Torrie wrote:
>> You say you are trying to use a singleton pattern, but your code does
>> not appear to implement a singleton.  From what I can read of your code,
> 
> I call it a singletone because I only every create one object.
> 
> I am not trying to use a singleton, I'm trying to avoid issues created by the
> alternative ways of doing this (not having access to the variables in the repl
> etc...).
>
> There are type of problems where I don't want to bind functions to data.
>
> By the way, I have just added some more explanation in the code,
> trying to clarify the problem.

I suppose it's just a matter of style but I'd just have my utility
function return a dict of all the calculated values, rather than store
them in a utility class instance.  Then you wouldn't need an
intermediate object to hold state temporarily. The idea behind
functional programming in part is you can chain things together easily
should you need to, which your intermediate object cannot do.

But I do see kind of the pattern you are trying to employ here; I just
don't understand why it's required or what you'd use it for, given that
a function could just do all the calculations and return a list or dict
of all calculated the values.






More information about the Python-list mailing list