Finding the instance reference of an object

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Nov 4 20:21:02 EST 2008


On Tue, 04 Nov 2008 16:02:29 -0700, Joe Strout wrote:

> 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.)

Yeah, we are all wrong and you are right.  Because you say so and ignore 
messages that might have facts that are not good for your blood 
pressure.  Very convincing.

> 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++.

But we have no pointers in Python.  "Pointer" is a data type in C and C++ 
but Python, the language, has no such type.

> 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.

Guess what, I find call-by-value in Java for objects the wrong term too.  
Same reason: Java has no pointer or reference as data type.

>> 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, […]

You have said the value that is copied is a pointer to the object.  So 
the value in your call-by-value is something that doesn't exist in the 
Python language.

> 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).

That's just because you seem to insist that a "variable" is a name for a 
memory location.  A variable brings together name, type, memory location, 
and a value, and in Python type and memory location are attached to the 
value and not the name, like in C++ for example.

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

I think explaining that the object is shared, or given another name 
locally, is much simpler than to explain the underlying machinery two 
levels below (because the CPython-VM doesn't know pointers either).  
Maybe not for people who know that low levels from older languages and 
insist on explaining everything in the terms of those.  Maybe that's the 
reason for the Java folks to call their strategy call-by-value, because 
they were afraid to confuse C++ programmers with "new" concepts.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list