Finding the instance reference of an object

Joe Strout joe at strout.net
Thu Oct 30 11:03:42 EDT 2008


On Oct 30, 2008, at 7:56 AM, Dale Roberts wrote:

>> That's the misconception that is leading some folks around here into
>> tangled nots of twisty mislogic, ultimately causing them to make up
>> new terms for what every other modern language is perfectly happy
>> calling Call-By-Value.
>
> Doesn't this logic also apply to Call By Reference? Isn't that term
> redundant too? (see my 3 C++ examples above). If not, why not?

It's not.  Wikipedia explains the difference pretty well.

> Are you saying that C++ is capable of using the Call By Reference  
> idiom,
> but C is not, because C does not have a reference designation for  
> formal
> function parameters?

It's been a LONG time since I did anything in C, but yes, I believe  
that reference parameters were an addition that came with C++.

> "Call By Object Reference" is an idiom, just like Call By Reference.
> It is not a physical description of what is going on internally at the
> register/stack level (which is always just shuffling values around -
> or flipping bits, as Steven points out), it is a higher level concept
> that helps people understand the *intention* (not necessarily the
> implementation) of the mechanism.

Right.  And you can easily tell the difference, by whether an  
assignment to the formal parameter causes any change to the actual  
parameter that was passed in.  If it does, that's call-by-reference.   
If it doesn't, it's call-by-value.  In Python, it doesn't.  In VB.NET  
(and relatives), it doesn't if the parameter is declared (explicitly  
or implicitly) "ByVal", and does if it's declared "ByRef".  (Whether  
the parameter is a reference type or a simple value type makes no  
difference.)

Python's behavior is exactly and always equivalent to the "ByVal"  
behavior of languages that have both behaviors.  It also matches the  
definition of call-by-value.  I quite agree that it's not helpful to  
delve into the physical flipping of transistor states.  We're talking  
about the behavior, and the behavior, very clearly, is call-by-value.   
To call it something else only clouds the issue and results in  
confusion.  (Perhaps explaining why there appears to be far more  
confusion about call semantics in the Python community than in the  
community of other languages where the default semantics are exactly  
the same.)

Best,
- Joe





More information about the Python-list mailing list