coding style - where to declare variables
steve+comp.lang.python at pearwood.info
Mon Jul 23 07:26:50 EDT 2018
On Mon, 23 Jul 2018 11:49:37 +0300, Marko Rauhamaa wrote:
> People new to Python are unnecessarily confused by talking about names
> and binding when it's really just ordinary variables and assignment.
It really isn't, not to those people who expect ordinary variables and
assignment to be the same as that of C, C++, C#, Objective C, Swift,
Pascal, Java, Go etc.
There are at least two common models for the association between symbolic
names and values in programming:
1. variables are named boxes at a statically-allocated, fixed
location in memory, usually on the stack ("value types");
2. variables are names that refer to dynamically-allocated
objects in the heap, often movable ("reference types").
It is absolutely true that both are "variables" of a kind, and that "name
binding" is abstract enough to refer to both models. But in *practice*,
the influence of Algol, C and BASIC especially is so great that many
people think of variables and assignment exclusively in the first sense.
Since Python uses the second sense, having a distinct name to contrast
the two is desirable, and "name binding" seems to fit that need.
I no longer believe that we should actively avoid the word "variable"
when referring to Python. I think that's an extreme position which isn't
justified. But "name binding" is an accurate technical term and not that
hard to understand (on a scale of 0 to "monad", it's about 1) and I think
it is elitist to claim that "people new to Python" will necessarily be
confused and we therefore ought to avoid the term.
There are lots of confusing terms and concepts in Python. People learn
them. Name binding is no different.
 What, all of them? Even those with a comp sci PhD and 40 years
programming experience in two dozen different languages?
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list