I'm wrong or Will we fix the ducks limp?

Steven D'Aprano steve at pearwood.info
Mon Jun 6 12:19:47 EDT 2016


On Mon, 6 Jun 2016 04:37 pm, Gregory Ewing wrote:

> Steven D'Aprano wrote:
>> The *name* "x" is an entity which is bound to (i.e. a reference to) the
>> object 99, in some specific namespace, at some specific time. The name
>> itself is an English word consisting of a single letter, "x".
> 
> This is one reason why the term "name" is not good subsitute
> for the term "variable". The string "x" is not the same thing
> as the variable x, a fact that's obscured if you call the
> variable a "name".

I never said that the string "x" is the same thing as the variable x. I made
it clear, well I thought it was clear, that the *implementation* of names
in CPython uses string keys in dictionaries, but that's not what a name is.
A name is just a abstract, human-readable label. We prefer meaningful names
like "x" or "number_of_pages", but an interpreter could use 64-bit
cryptographic hashes or UUIDs or whatever it likes.

(A Python interpreter would have to find some way to map those UUIDs back to
human readable strings, so that we can call vars() or globals() or
equivalent and see the names we expect. But another language need not do
that.)


> A better analogy along the presidential line would be the
> name "President of the United States". That name can refer
> to different people at different times, so there must be
> some piece of state in the world that records the association
> between the character string "President of the United States"
> and the person who currently holds that office.

How ironic, after telling me off for saying that variables were strings
(which I didn't do), you're now talking about the POTUS being a "character
string".

You are right that there must be some piece of state that associates the
label "POTUS" or "Barack Obama" with the man. That's the essential feature
of a name binding. In human languages, we generally use words for labels.
(Sometimes we use numbers, as in "Prisoner 23848".) But we also need to
distinguish between talking about the POTUS and talking about the
*label* "POTUS", and the usual way of doing that in English is as I just
did, but putting it in quotation marks, or referring to it as "the word
POTUS", or some other equivalent phrase.


> It's that piece of state that the OP is calling a "box".
> I don't know what form it actually takes, probably an
> official piece of paper somewhere, which may well be
> kept in a box. But the box doesn't contain Barack Obama
> himself, it only contains something that refers to him.

Yes. And? 

Two points:

(1) When we refer to Barack Obama, we're not referring to his birth
certificate, and when we refer to the POTUS, we're not referring to this
hypothetical box where the official piece of paper resides. We're referring
to the man. Just as when we refer to the x in "x = 999", we mean 999, not
some analogue to a birth certificate or certificate of being president.

(2) The "variables are like boxes" metaphor applies to static languages like
C and Pascal, where the compiler has knowledge of what variables will
exist. Such languages allocate space for the variables at compile time,
usually using fixed memory locations on the stack, or in registers, but
rarely dynamically in the heap. That's exactly what Python doesn't do.



-- 
Steven



More information about the Python-list mailing list