PyMyth: Global variables are evil... WRONG!
Tim Daneliuk
tundra at tundraware.com
Mon Nov 11 21:47:09 EST 2013
On 11/11/2013 08:06 PM, Rick Johnson wrote:
> Globals are justified when they are used to communicate
> information between scopes that otherwise were meant to be
> mutually exclusive.
I think this is certainly the use case most people would suggest.
But I think you may have missed the real reason most modern
designers object to inter-module globals: The presence of
such entities almost always means the code has been designed
badly. Whether we're writing pristine OO code (cough, cough)
or more traditional procedural stuff, information hiding
is a good thing. When and where there is a need for modules
(or programs, or machines, or "clouds", or interstellar space ...)
to share information, my view is this is better done via some sort
of interface/message passing mechanism. The more "things" that have
to be shared across modules/programs/machines/clouds/space ... the more
*brittle* the end system becomes.
This problem is broader than just variables, BTW. It exists anytime you
share *anything* across many computational components, especially in highly
parallel and/or distributed systems. For example, RPCs tend to be lousy
at building high scale distributed system because they usually have
a call-and-wait semantic which will fail if the caller never responds.
In this case the system is sharing the semantics of *time*. As a general
matter, exactly-once asynchronous messaging tends to be a better implementation
model here.
Just my 2 cents worth. Interesting read. Thanks for taking the time
--
----------------------------------------------------------------------------
Tim Daneliuk tundra at tundraware.com
PGP Key: http://www.tundraware.com/PGP/
More information about the Python-list
mailing list