Explaining names vs variables in Python

Steven D'Aprano steve at pearwood.info
Wed Mar 2 20:52:26 EST 2016


On Thu, 3 Mar 2016 05:12 am, Marko Rauhamaa wrote:

> Steven D'Aprano <steve at pearwood.info>:
> 
>> In this case, "same object" carries the normal English meaning of
>> "same" and the normal computer science meaning of "object" in the
>> sense of "Object Oriented Programming". There's no mystery here, no
>> circular definition.
> 
> I see three possible ways of defining "is" / object identity (and other
> concepts):
> 
>    1. hand waving ("normal English")
> 
>    2. reduction to an underlying model (a real / conceptual computer)
> 
>    3. formal semantics
> 
> All methods are in use. Experienced programmers have #2 in mind but are
> embarrassed to admit they understand Python through C. Thus, they offer
> explanation #1 to newbies, who are too embarrassed to admit they don't
> get the explanation.

There is no evidence that newbies "don't get the explanation". Completely
the opposite: newbies frequently find the behaviour of `is` mysterious[1]
*until* it is explained to them in terms of "same object", after which it
becomes clear. (At least for those who understand what "object" means in
OOP terms.)

And then the same two people, you and Rustom, come along and insist that the
docs don't define `is` correctly and raising irrelevant philosophical
objections. But there's no evidence that these issues are the least bit
relevant to the newbies who asked the questions in the first place.


> I think #3 could be tried more often. 

I completely agree! It could be tried more often!

Other things that could be tried more often include:

- defining `is` through the medium of interpretive dance;

- defining `is` by wafting information-rich pheromones through the air;

- defining `is` by taking copious amounts of hallucinogens until your mind
becomes one with the universe and you intuitively understand everything.

But I think that in the case of Python, a combination of #1 and #2 are
needed.

(I think that nearly all people need to have some sort of concrete picture
in their heads for an object, even if they then go on to consciously reject
that picture as "just an implementation detail". Objects are not
necessarily C structs with a pointer back to a struct which represents the
object's class, but that's a common implementation.)



> It is analogous to providing the 
> BNF of Python's syntax (which *is* done: <URL:
> https://docs.python.org/3/reference/grammar.html>).

BNF is for describing syntax, not semantics. Nobody has trouble with the
syntax of `is`, it is a simple binary operator. There is no analogous
BNF-equivalent for semantics.





[1] Usually because they are either interpreting it as a synonym for
equality, or because they are confused by Python's caching of small ints
and some strings.


-- 
Steven




More information about the Python-list mailing list