Python handles globals badly.
Steven D'Aprano
steve at pearwood.info
Thu Sep 3 22:33:53 EDT 2015
On Fri, 4 Sep 2015 05:05 am, tdev at freenet.de wrote:
> Would you remove this keyword if it would be technically possible
Absolutely not.
I do not believe that it is technically possible, but even if it were, I
would still argue that the Zen of Python applies:
Explicit is better than implicit.
Local variables should be the default, and you should explicitly declare any
time you want to write to a global.
Not the other way around, like Lua does. I've always thought that was silly:
you should make the *desirable* thing easy to do, and the *dangerous* think
(using globals) possible but not easy to do by accident.
> or is good for you from high level point of view to have a keyword
> "global"?
Yes.
> My answer is clear: remove it.
> [The same e.g. with switch statement: add it]
What would a switch statement do? How will it be different from if...elif?
Out of the dozen or so different switch statements offered by other
languages, which would you choose?
--
Steven
More information about the Python-list
mailing list