Steven D'Aprano steve at pearwood.info
Fri Jan 4 22:51:39 EST 2019

On Fri, Jan 04, 2019 at 06:15:11PM -0600, Abe Dillon wrote:

> Sure everyone knows what it means, but it's meaning is essentially useless
> because the default assumption when you encounter a variable you don't
> know, is that you shouldn't overwrite it. If you found a module-level
> variable in Pandas named cucumber, would you immediately assume you can
> write whatever value you want to pandas.cucumber because it isn't in all
> caps?

Code is read more often than it is written.

The important question is rarely "can I overwrite random variables?" but 
is usually "what is the value of this variable right now?".

If I see a call like:


I may have no idea what cucumber holds, or where to find its binding. I 
may have to work hard to determine

(1) where it is initially bound;

(2) whether or not it has been, or could be, rebound to something else;

(3) and what value it holds at the time it is passed to the function.

If cucumber is a *variable*, that's kind of unavoidable, its part of 
what makes programming so ~~frustrating~~ fun and why we have debuggers, 
tracing and the venerable old technique of inserting print() calls to 
find out what's going on in our code.

But if I see:


that tells me that in idiomatic Python code, CUCUMBER is a constant 
bound close to the top of the module, and never rebound.


More information about the Python-ideas mailing list