IsString

Donn Cave donn at u.washington.edu
Wed Dec 14 17:03:58 EST 2005


In article <1134553148.562428.79170 at o13g2000cwo.googlegroups.com>,
 "Ben Sizer" <kylotan at gmail.com> wrote:
> Steven D'Aprano wrote:
> > def modify_in_place(obj):
> >     """Modify an arbitrary object in place."""
> >     obj = None
> >
> > x = [1, 2, 3] # mutable object
> > modify_in_place(x)
> > assert x is None
> >
> >
> > Doesn't work either.
> 
> To be fair, this isn't because the function is not pass by reference,
> but because the assignment operator reassigns the reference rather than
> altering the referent, and thus modify_in_place doesn't actually
> contain any modifying operations. With a good understanding of what
> Python's assignment operator actually does, (I believe) you can view
> Python as pass-by-reference without any semantic problems.

What he said!

While I agree (with another post) that there seems to be
a difference in perspective that depends on what language
you were using when you first heard these terms, in the
end it really seems sort of almost disingenuous to argue
that the "value" in question is actually a pointer.  (The
pointer is in a practical sense a reference, so what if we
say "pass by reference value?!"

I would like to argue that "value" basically means the
computational effect.  In "s = a + b", the value of "b"
is whatever ends up applied to that "+" operator.  In
isolation, the value of some object is its computational
potential - the object isn't its value, rather the
implementation of the value.  Parameter passing isn't
a computation in this sense, and it doesn't make sense
for it to have its own interpretation of "value".

--

Historically, the way I remember it, there was a time not too
long ago when GvR and his minions sort of dismissed the idea
that you needed to understand the reference/object model from
the outset.  I mean, obviously you need to get there eventually
if you're going to be a hard core Python programmer, but they
wanted to see people learning to write programs, without being
encumbered by knowledge of implementation details, and ideas
about the difference between "variable" and "binding" are
certainly about implementation details.

It depends on your ambitions, I suppose, whether that's really
a good idea, since there's no question that some understanding
of the principles involved has to come fairly early.  But I think
we really lose out when we try to make it be about the words -
"Python doesn't have variables"/"Does too", "Python passes by
value"/"Does not", etc.  When the words really clearly express
the right thing to anyone with a reasonable background, that's
great.  But usually, they don't.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list