Modifying Class Object

Alf P. Steinbach alfps at start.no
Tue Feb 9 07:35:57 CET 2010


* Stephen Hansen:
> On Mon, Feb 8, 2010 at 8:01 PM, Alf P. Steinbach <alfps at start.no 
> <mailto:alfps at start.no>> wrote:
> 
>     * Stephen Hansen -> Alf P. Steinbach:
> 
> 
>         [snip]
> 
>         To say, "pass by value" implies things to people. It describes a
>         sort of world where I'm a function about to do some work, and on
>         my desk I have a series of boxes with names on it. It describes
>         an environment where someone comes over and drops something into
>         each of my boxes. The contents of these boxes are mine alone!
> 
> 
>     Then, when the imprecision makes people misunderstand, one should
>     not say that.
> 
>     One should then be more precise.
> 
>     One should say /what/ is passed by value.
> 
> 
> No.
> 
> One should not use the phrase that is fundamentally imprecise.
> 
> The phrase "pass by value" means something different then the phrase 
> "pass by object" aka "pass by sharing". They are in many cases very 
> similar. They are not the same.

Right.

"pass by value" is a lower level notion.

And as you show below, in the paragraph marked [1], it can be used to describe 
call by sharing very succinctly and precisely, just as I did... ;-)


> Using it is simply wrong. There is 
> really no legitimate argument you can make otherwise: even in languages 
> where call-by-value IS the norm, the phrase is imprecise enough to 
> confuse people, as the semantics of what call-by-value mean to a 
> language vary. But those semantics do NOT apply to Python.

In a way that's right, but only at the level of abstraction of pass by sharing.

At that level it's wrong to say that pass by sharing is pass by value (as they 
reportedly do over in Java-land), just as, at that level, it's wrong to say that 
pass by reference is pass by value notwithstanding that some kind of value must 
be copied in the internal implementation.

Describing pass by sharing in terms of pass by value is however very simple and 
legitimate, involving a higher level described in terms of a lower level  --  as 
you illustrate right below: <g>


>     [snip]
>         I know you already know this, but the point is: you're -hurting-
>         other peoples understanding by using terms like this that don't
>         apply to Python's specific nature.
>     The terms apply very well to Java. And Java has the identical
>     parameter passing mechanism for class type objects. Hence, the
>     argument is bogus.
> 
> 
> [1] Java uses silly terminology; and that it chooses to use silly 
> terminology in no way impacts the validity of the argument. Java isn't 
> an authority. Python's been around longer! And the specific behavior 
> here, "call by value where the value is an object reference" was named 
> "call by sharing" back in the 1970's by Liskov.

Yep.

As you write, "call by sharing" can be described as "call by value where the 
value is an object reference".

Althuogh I'd rather use "where the value is an object pointer", because the word 
"pointer" already denotes a copyable value so doesn't make the head spin...


> Java isn't call-by-value (for objects) either, even if that phrase is 
> common in the Java community.

Right, and here the parenthesis (for objects) establishes which abstraction level.


> C is call-by-value. VB is, I believe, 
> call-by-value -- though I may be wrong here, as I only sort of blinked 
> at VB a long, long time ago. 

Full VB supports both call by sharing and call by reference.


> Its distinct. Its different. Its neither call-by-value, nor 
> call-by-reference. The /value/ of a thing is NOT its identity. Its the 
> /state/ of that thing.

Talking about a reference value (a.k.a. pointer), as you do earlier above in 
[1], does not mean that one is talking about a Python object value.

So essentially the paragraph immediately above seems to be a confusion based on 
multiple meanings of "value", unless it's just a description of Python objects?


> By your argument, call-by-reference is call-by-value too! Because you're 
> passing "a value" -- but you're -always- going to pass some piece of 
> data, otherwise you're not actually passing anything. 

No, whatever you think my argument is (no quote, so I'm left in the dark about 
that assumption) here you're back to confusing levels of abstraction again.

Call by reference is necessarily, at some level, implemented in terms of call by 
value.

That doesn't make call by reference the same as call by value, not more than the 
human body is one giant molecule just because it consists of molecules.


> The /by value/ vs /by reference/ vs /by sharing/ is not about "is a 
> value being passed", in all cases, "a value" is. By Value means a copy 
> of the thing is made. By Reference means you're accessing the callers 
> variable directly. By Sharing means you're both sharing the same object.

Yes, violent agreement.


>     PS: I cannot see any of your postings on Usenet. So I just sort of
>     grabbed this from GMane and posted to Usenet. Hopefully you'll see
>     it back at the list. :-)
> 
> 
> I've heard that before, and have no idea why, nor any real interest in 
> solving it: I don't want to read cpl via Usenet, and prefer to read it 
> as a mailing list. Somewhere between Gmail->python.org->python.org 
> <http://python.org>'s usenet server->the world, some people don't seem 
> to get my posts. Yet it shows up on some news servers, not others.
> 
> No idea. Nothing I know of can solve it.

Not sure, but perhaps it's possible to mail directly to gmane?


Cheers & hth.,

- Alf



More information about the Python-list mailing list