From: MRAB on
Alf P. Steinbach wrote:
> * Chris Rebert:
>> On Sun, Feb 7, 2010 at 5:05 PM, T <misceverything(a)gmail.com> wrote:
>>> Ok, just looking for a sanity check here, or maybe something I'm
>>> missing. I have a class Test, for example:
>>>
>>> class Test:
>>> def __init__(self, param1, param2, param3):
>>> self.param1 = param1
>>> self.param2 = param2
>>> self.param3 = param3
>>>
>>> Next, I have a dictionary mytest that contains instances of Test. If
>>> I want to modify one of the Test instances within my dictionary, I
>>> have to rewrite the entire entry, correct (since Python passes by
>>> value, not reference)?
>>
>> Incorrect; Python uses neither. See
>> http://effbot.org/zone/call-by-object.htm for a excellent explanation
>> of what Python does use.
>
> Hm. While most everything I've seen at effbot.org has been clear and to
> the point, that particular article reads like a ton of obfuscation.
>
> Python passes pointers by value, just as e.g. Java does.
>
> There, it needed just 10 words or so. :-) Or perhaps some more words to
> point out that in the Java language spec those reference values are
> called pointers, but that this terminology isn't (apparently) used for
> Python, and isn't even well known among Java programmers. But that's
> just one extra little para.
>
> One just has to be clear about exactly what it is that's passed by value.
>
> Not Python objects, but references (pointers) to them, the id(o) values.
>
A reference is not the same as a pointer.

A pointer tells you where something is; a reference doesn't.
From: Alf P. Steinbach on
* MRAB:
> Alf P. Steinbach wrote:
>> * Chris Rebert:
>>> On Sun, Feb 7, 2010 at 5:05 PM, T <misceverything(a)gmail.com> wrote:
>>>> Ok, just looking for a sanity check here, or maybe something I'm
>>>> missing. I have a class Test, for example:
>>>>
>>>> class Test:
>>>> def __init__(self, param1, param2, param3):
>>>> self.param1 = param1
>>>> self.param2 = param2
>>>> self.param3 = param3
>>>>
>>>> Next, I have a dictionary mytest that contains instances of Test. If
>>>> I want to modify one of the Test instances within my dictionary, I
>>>> have to rewrite the entire entry, correct (since Python passes by
>>>> value, not reference)?
>>>
>>> Incorrect; Python uses neither. See
>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation
>>> of what Python does use.
>>
>> Hm. While most everything I've seen at effbot.org has been clear and
>> to the point, that particular article reads like a ton of obfuscation.
>>
>> Python passes pointers by value, just as e.g. Java does.
>>
>> There, it needed just 10 words or so. :-) Or perhaps some more words
>> to point out that in the Java language spec those reference values are
>> called pointers, but that this terminology isn't (apparently) used for
>> Python, and isn't even well known among Java programmers. But that's
>> just one extra little para.
>>
>> One just has to be clear about exactly what it is that's passed by value.
>>
>> Not Python objects, but references (pointers) to them, the id(o) values.
>>
> A reference is not the same as a pointer.

Depends on your choice terminology. I referred to the Java (language spec)
terminology to make it clear.


> A pointer tells you where something is; a reference doesn't.

Sorry, I don't know of any relevant terminology where that is the case.


Cheers & hth.,

- Alf
From: Steve Holden on
Alf P. Steinbach wrote:
> * MRAB:
>> Alf P. Steinbach wrote:
>>> * Chris Rebert:
>>>> On Sun, Feb 7, 2010 at 5:05 PM, T <misceverything(a)gmail.com> wrote:
>>>>> Ok, just looking for a sanity check here, or maybe something I'm
>>>>> missing. I have a class Test, for example:
>>>>>
>>>>> class Test:
>>>>> def __init__(self, param1, param2, param3):
>>>>> self.param1 = param1
>>>>> self.param2 = param2
>>>>> self.param3 = param3
>>>>>
>>>>> Next, I have a dictionary mytest that contains instances of Test. If
>>>>> I want to modify one of the Test instances within my dictionary, I
>>>>> have to rewrite the entire entry, correct (since Python passes by
>>>>> value, not reference)?
>>>>
>>>> Incorrect; Python uses neither. See
>>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation
>>>> of what Python does use.
>>>
>>> Hm. While most everything I've seen at effbot.org has been clear and
>>> to the point, that particular article reads like a ton of obfuscation.
>>>
>>> Python passes pointers by value, just as e.g. Java does.
>>>
>>> There, it needed just 10 words or so. :-) Or perhaps some more words
>>> to point out that in the Java language spec those reference values
>>> are called pointers, but that this terminology isn't (apparently)
>>> used for Python, and isn't even well known among Java programmers.
>>> But that's just one extra little para.
>>>
>>> One just has to be clear about exactly what it is that's passed by
>>> value.
>>>
>>> Not Python objects, but references (pointers) to them, the id(o) values.
>>>
>> A reference is not the same as a pointer.
>
> Depends on your choice terminology. I referred to the Java (language
> spec) terminology to make it clear.
>
>
>> A pointer tells you where something is; a reference doesn't.
>
> Sorry, I don't know of any relevant terminology where that is the case.
>
Alf:

This topic was discussed at great, nay interminable, length about a year
ago. I'd appreciate it if you would search the archives and read what
was said then rather than hashing the whole topic over again to nobody's
real advantage.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

From: Steven D'Aprano on
On Sun, 07 Feb 2010 22:03:06 -0500, Steve Holden wrote:

> Alf:
>
> This topic was discussed at great, nay interminable, length about a year
> ago. I'd appreciate it if you would search the archives and read what
> was said then rather than hashing the whole topic over again to nobody's
> real advantage.

Curse you Steve, I had just come up with a brilliant rebuttal of Alf's
position. It was sheer genius, the sort of thing that would have James
Gosling weeping with envy.

Oh well, into the bitbucket it goes...


--
Steven
From: alex23 on
"Alf P. Steinbach" <al...(a)start.no> wrote:
> Hm. While most everything I've seen at effbot.org has been clear and to the
> point, that particular article reads like a ton of obfuscation.

Must. Resist. Ad hominem.

> Python passes pointers by value, just as e.g. Java does.
>
> There, it needed just 10 words or so. :-)

10 words _plus_ an understanding of Java. Do you really think its
appropriate to discuss Python's behaviour purely in terms of other
languages?

Further, you've managed to define Python's behaviour as being somehow
_both_ of the major evaluation strategies - calling a reference by
value - so you're asking people to understand two totally irrelevant
models just to avoid describing one in its own terms. Rather than
arguing about whether you have a 'value' or a 'reference', it's a lot
easier to explain that you're passing mutable & immutable objects
around. The behaviour is thus defined in terms of the object and _not_
in the calling model, and is far more consistent with object
references throughout the language. It also doesn't require reference
to other languages simply to define Python's model in terms of what it
isn't.