PyMyth: Global variables are evil... WRONG!

Steven D'Aprano steve at pearwood.info
Thu Nov 14 01:25:43 EST 2013


On Wed, 13 Nov 2013 23:33:22 -0500, Roy Smith wrote:

> In article <mailman.2580.1384399784.18130.python-list at python.org>,
>  Chris Angelico <rosuav at gmail.com> wrote:
> 
>> I have yet to see any language that gives true globals. At very best,
>> they're just process-wide! Honestly. How am I supposed to write code
>> that accesses variables running on my New York server?
> 
> Any one of a slew of remote procedure call protocols.  These days, the
> cool kids are using REST, but people have been doing RPC-ish things ever
> since the first guy to connect two computers with a piece of wire.

Nice Devil's Advocacy :-)

But of course, there are differences between the two situations. In a RPC, 
you have to use a defined interface to reach across the wire, so to 
speak, rather than have the two machines intimately coupled in a single 
namespace.

It is true that you can write RPC code that is highly coupled. Such 
highly coupled code is harmful whether it occurs due to global variables 
or via RPC calls or some other mechanism. But the difference is you have 
to work at it to write such highly coupled code with RPC calls, while 
with single-process globals such coupling occurs naturally without effort.


-- 
Steven



More information about the Python-list mailing list