Chris Angelico rosuav at gmail.com
Fri Jan 4 18:41:04 EST 2019

On Sat, Jan 5, 2019 at 10:29 AM Abe Dillon <abedillon at gmail.com> wrote:
>> How do you propose, instead, for the constantness of something to be indicated?
> That's a good question. I honestly don't use constants all that much...

Just to be clear here: you're trying to say that the ALL_CAPS_NAME
convention is unnecessary, but you don't use constants. That kinda
weakens your argument a bit :)

> 1) provide a property to access an otherwise _plz_dont_touch_variable
> 2) Use an Enum
> 3) Use documentation to say: treat this as constant
> 4) Rely upon consenting adults to not change variables outside of scope. It's weird to manipulate math.pi because it's in a separate module.
> I stopped using all caps a long time ago and it just hasn't created a problem because manipulating global variables without knowing what they are is such a bad idea to begin with.

The whole point of the all-caps globals is to tell you a lot about
what they are. For instance, I will often use a module-level constant
for a file or path name; within the module, it is deliberately treated
as a constant, but if you import the module somewhere else, you could
reassign it before calling any functions in the module, and they'll
all use the changed path.

We use well-chosen variable names to avoid needing special properties
or documentation to explain how something is to be used. It's far
better to distinguish between "thing" and "things" than to have to say
"thing" and "array_of_thing". The whole "consenting adults" policy has
to be built on clear indications, and the name of something is a vital
part of that.

It's up to you whether you actually use the all-caps convention in
your own code or not, but IMO it is an extremely useful convention to
have in the toolbox, and should be kept.


More information about the Python-ideas mailing list