A question on modification of a list via a function invocation

Ben Bacarisse ben.usenet at bsb.me.uk
Thu Aug 17 09:37:43 EDT 2017


Steve D'Aprano <steve+python at pearwood.info> writes:

> On Thu, 17 Aug 2017 10:14 am, Ned Batchelder wrote:
<snip>
>> For some reason, students have been taught that things can be either
>> call-by-reference or call-by-value. But those are not the only two
>> possibilities, and neither completely describes how Python works.

That's obviously a crying shame when it happens, but I don't think it's
universally true.  Neither my experience as a student nor as a teacher
bear this out.

<snip>
> Indeed. The insistence on this false dichotomy of call by value versus by
> reference puzzles me, since alternatives go back to one of earliest, and most
> influential, programming languages: Lisp. Algol, another early and hugely
> influential language, used call by name.
>
> Its like there was an entire generation of cooks and chefs who insisted that
> there are only two ways of cooking food: steaming, and barbecuing, and came up
> with elaborate rationalisations for why frying, roasting, boiling etc are
> actually one of the two.

Obviously it's better (as Ned also said) to learn a language using its
own terms, but sometimes it can help to make the jump from one language
to another to think about it in other, less specific, jargon.

What goes wrong when someone thinks of Python as passing by value but
the value of an expression is an object reference?  (I'd rather avoid
the term "reference" altogether and talk, instead, about an object's
identity, but Python already uses that term.)

I know you address this exact question in relation to Java (sorry, I cut
it because I'm not commenting on it) but I don't know Java at all, and I
only know Python as a casual user so I can't evaluate how well the
arguments carry over.

<snip>
-- 
Ben.



More information about the Python-list mailing list