Finding the instance reference of an object

Joe Strout joe at
Fri Oct 17 23:39:33 CEST 2008

On Oct 17, 2008, at 3:19 PM, Grant Edwards wrote:

>> And my real point is that this is exactly the same as in every
>> other modern language.
> No, it isn't.  In many other languages (C, Pascal, etc.), a
> "variable" is commonly thought of as a fixed location in memory
> into which one can put values.  Those values may be references
> to objects.

Right, though not in languages like C and Pascal that don't HAVE the  
notion of objects.  We really ought to stop bringing up those  
dinosaurs and instead compare Python to any modern OOP language.

>  In Python, that's not how it works.  There is no
> "location in memory" that corresponds to a variable with a
> particular name the way there is in C or Pascal or Fortran or
> many other languages.

No?  Is there any way to prove that, without delving into the Python  
source itself?

If not, then I think you're talking about an internal implementation  

> All that exists in Python is a name->object mapping.

And what does that name->object mapping consist of?  At some level,  
there has to be a memory location that stores the reference to the  
object, right?

>> Nothing unusual here at all (except that some of us here seem
>> to want to make up new terminology for standard behavior,
>> perhaps in order to make Python seem more exotic).
> That's because it is fundamentally different from what happens
> in languages like C.

What happens in a modern OOP language is just as fundamentally  
different (which is to say, not really very much) from what happens in  
C or FORTRAN or COBOL, too.

But if there's any demonstrable difference between Python and any  
other modern OOP language, I'd love to hear about it.

>>> a = a + [something]
>>> rebinds a
>> In standard terminology, it assigns a new value to a.
> The problem is that listeners from a C or FORTRAN background
> will infer that there is a fixed region of memory named "a" and
> "assigning a value to a" means writing that new value into the
> region of memory named "a".

And they'd be correct.  The value being written, in this case, as a  
reference to some data that lives somewhere on the heap.  Point that  
out, and now their understanding is correct.

But if you instead say something like "all parameters are passed by  
reference in Python," then the user gets the wrong idea.  That  
statement has a specific meaning which is, quite demonstrably, not true.

If you make up new terms like "rebinds," well, I guess at least that  
avoids giving the listener the wrong idea.  Instead it gives them no  
idea at all, which may be better, but not as good as giving them the  
right idea.  It still leaves them to investigate what actually  
happens, and ultimately they will find that the parameters are always  
passed by value in Python.  May as well save them the trouble and  
point that out up front.

And how many recovering FORTRAN or C programmers do we get around  
here, anyway?  Java is what they've been teaching in school for the  
last several years, and it was C++ for a good decade before that.  The  
semantics of Python (insofar as objects, assignments, and parameters  
are concerned) are exactly the same as Java, and Java is just a  
cleaned-up and streamlined C++.  Even old-timers (like me) who learned  
FORTRAN and COBOL way back in the day have long since moved on.

- Joe

More information about the Python-list mailing list