Finding the instance reference of an object

Fuzzyman fuzzyman at gmail.com
Thu Oct 30 13:12:08 CET 2008


On Oct 30, 1:13 am, Joe Strout <j... at strout.net> wrote:
> On Oct 29, 2008, at 4:52 PM, Fuzzyman wrote:
>
> > You're pretty straightforwardly wrong. In Python the 'value' of a
> > variable is not the reference itself.
>
> 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.
>
> I've thought a lot about why this misconception is so widespread here,
> and I think it must be one of the following:
>
> 1. There was one community leader with this idea, who has been
> successful at promoting it widely, much to the detriment of all; or,
>
> 2. Because everything in Python is an object, you're not forced to
> think clearly (and more generally) about references as values as you
> are in languages (such as Java, VB.NET, etc.) which have both simple
> types and object types.
>


To make it clearer for you, call by value means that the value is
copied in - and therefore changes to the value won't be visible to the
caller.

In .NET this is true of mutable value types - changes made are made to
a copy and not visible to the caller. In Python we *only* have
reference types, so changes to *any* mutable object are visible to the
caller.

In .NET you can call by reference with a value type - and the runtime
does boxing for you so that you can see the changes. You have to
explicitly ask for call by reference though.

Michael

> Either way, it's wrong (or at least, a needlessly complicated way of
> looking at things).
>
> > .NET does draw a distinction between 'value types' and reference types
> > - where using reference types are called by reference (the reference
> > is passed) and value types are called by value (the value itself is
> > copied).
>
> Quite right.  Now, note that "ByRef" and "ByVal" apply to both.
> Generalize to Python.  There you go.
>
> Best,
> - Joe
>
> P.S. I really am trying to quit responding to this thread.  Sometimes
> the urge is too strong.  But I'll keep trying!




More information about the Python-list mailing list