Finding the instance reference of an object

Joe Strout joe at strout.net
Tue Nov 4 18:02:29 EST 2008


On Nov 4, 2008, at 3:42 PM, Steven D'Aprano wrote:

>> This example is also call-by-value, but the value in this case is a  
>> type
>> that has no analog in Python.
>
> I'm disappointed to see that my prediction that Joe would, yet again,
> utterly ignore all the arguments against his pet theory was correct.

I'm not doing that, but the folks on the other side are.  (Well, I  
don't know if you are in particular, as I've been deleting your  
messages to save my blood pressure... this one caught my eye though,  
alas.)

For example: we have arguments that you can "modify" a parameter  
passed to a function in Python.  These ignore the fact that you can  
only use (dereference) that parameter to modify something else, no  
different from a pointer passed by-value in C/C++.  And, when a very  
simple test for by-reference is brought up (i.e. writing a Swap  
method), this gets ignored again and again, by the otherwise perfectly  
nice fellow I've been discussing this with privately for days.  There  
are many other examples.

It boils down to this: Python's behavior is demonstrably the same as  
any other modern OOP language, INCLUDING those that have both by- 
reference and by-value parameter modes, except that in Python (as well  
as Java), only the by-value mode is available.

This is easily shown, and I've done exactly that at <http://www.strout.net/info/coding/valref/ 
 >.

But I predict that you'll ignore all this evidence that goes against  
your pet theory, and continue to cause confusion and obfuscation on  
the topic.

> When we're talking about the value of a variable in Python, why on  
> earth
> would you drag entities that do not exist in Python into the  
> discussion?

I don't, but others do, for example bringing up C structs or C++  
objects on the stack, which don't exist in Python (Python objects live  
on the heap, and all you have on the stack are references to them; the  
proper C/C++ analogy is an object created with "new" and referenced  
entirely via pointers).

> That is too low a level. It's analogous to my earlier tongue-in-cheek
> suggestion that all languages are in fact call-by-bit-flipping:
> technically true at some level of explanation, but not at the level of
> the Python virtual machine.

I agree that we don't need to talk about bits.  But we do need to  
understand whether code such as:

   a = SomeClass()
   b = a

creates two objects, or merely two references to the same object.   
Once we know whether we're dealing with values or references, then  
everything else becomes simple and clear, no matter what language  
we're building in.

I know you really want Python to be unique and special -- and it is,  
in many ways, but this isn't one of them.  Python is an OOP language  
whose variables contain references to objects, and where such  
references are passed (by value) to methods, just like Java, and like  
the default parameter mode in VB.NET, REALbasic, and C++ (though those  
languages also offer a by-reference mode that Python and Java do not).

Your continued attempts to obfuscate this simple behavior does no  
credit to you or Python.

Best,
- Joe




More information about the Python-list mailing list