PyMyth: Global variables are evil... WRONG!

jongiddy jongiddy at gmail.com
Tue Nov 12 23:41:34 CET 2013


On Tuesday, November 12, 2013 5:00:37 PM UTC, Rick Johnson wrote: 
> 
> 
>    1. Accept that globals are useful, and make them
> 
>       available through a "real" global syntax, not
> 
>       some attribute of a module that "appears" to be
> 
>       local, but in reality is global. Then prevent
> 
>       external mutation of module attributes directly,
> 
>       and instead, require that mutation must follow a
> 
>       contract defined by internal module "setter"
> 
>       functions.
> 
> 
> 
>    2. Remain convinced that global mutation is evil
> 
>       and prevent mutation of all python module
> 
>       attributes. You can import modules, but you can't
> 
>       mutate their contents.

>From your first post, I take it you're not keen on option #2.

For #1, module globals are exactly the hierarchically namespaced globals that you desire in your first post, except they are variables, not get/set handlers (which is what I take you to mean by an "interface").

Why not create a PEP to provide handlers for module attributes? You could base it on PEP 213, which describes the same feature for classes.

As a bonus, this would trivially support option #2 (e.g. non-mutable math.pi) by raising an exception for the set operator.



More information about the Python-list mailing list