Author noxdafox
Recipients noxdafox, sbt
Date 2013-10-09.18:56:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <5255A6C0.1030303@gmail.com>
In-reply-to <1381141979.01.0.783752722289.issue19185@psf.upfronthosting.co.za>
Content
On 07/10/13 13:32, Richard Oudkerk wrote:
> Richard Oudkerk added the comment:
>
> I think "misuse" is an exageration.  Various functions change some state and return a value that is usually ignored, e.g. os.umask(), signal.signal().
These functions are compliant with POSIX standards and the return values 
are actually useful, they return the previously set masks and handlers, 
often are ignored but in complex cases it's good to know their previous 
state.

The problem here is quite different, the interface is giving the 
opportunity of executing a function but it ignores the returned values, 
this is pretty limiting from an API point of view. It is quite 
counterintuitive and also not documented, proof is the amount of 
questions on how to use the initializer (just a couple of examples):
http://stackoverflow.com/questions/10117073/how-to-use-initializer-to-set-up-my-multiprocess-pool
http://stackoverflow.com/questions/9944370/use-of-initialize-in-python-multiprocessing-worker-pool
>
>> Global variables usage is a pattern which might lead to code errors and many
>> developers discourage from following it.
> What sort of code errors?  This really seems a stylistic point.  Maybe such developers would be happier using class methods and class variables rather than functions and globals variables.
http://c2.com/cgi/wiki?GlobalVariablesAreBad

It is a pretty common code practice to avoid global variables whenever 
possible; as always: is the way a tool is used to make it evil not the 
tool itself; yet I agree with the fact that a global variable change is 
hard to track down into the code and when the code grows it can lead to 
very tricky errors.
>
> Out of interest, what do you usually do in your initializer functions?
I mainly develop back-end systems which take great advantage from the 
Worker Pool pattern. We are talking about services which uses third 
party libraries to execute CPU bounded tasks trying to scale up with the 
number of CPU cores. Many of these libraries, unfortunately, are 
stateful (I would say "state-full") and their initialization is 
time-consuming.

Typically a worker initializes some of those objects (which currently 
are stored in global variables) and starts crunching some data, 
meanwhile the state of these objects keeps changing and here the global 
variables pattern shows its worst side.

>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue19185>
> _______________________________________
History
Date User Action Args
2013-10-09 18:56:03noxdafoxsetrecipients: + noxdafox, sbt
2013-10-09 18:56:03noxdafoxlinkissue19185 messages
2013-10-09 18:56:02noxdafoxcreate