passing by refference

Doug Quale quale1 at charter.net
Tue May 13 17:03:56 EDT 2003


aahz at pythoncraft.com (Aahz) writes:

> Note that I'm using "binding" instead of "reference"; like the mistaken
> use of "call-by-value", "reference" has semantics that make sense in
> other languages, but not in Python.

Actually call-by-value makes sense in Python and its use here is not
mistaken.  Call-by-value is the correct description of the semantics
of function calls in Python.  There's nothing mystical or even in the
slightest bit unusual with the way that Python passes arguments.
Claiming that Python argument passing is not call-by-value is simply
wrong and leads to needless confusion.

The problem isn't really with how Python function calls work.  Most
programmers seem to understand that just fine.  The confusion ensues
because people often don't really understand what a value is.  When
values are references call-by-value can seem to behave to some as
call-by-reference or even something else, but it's simply
call-by-value all the time.  (In the Python Tutorial Guido suggests
using the term call-by-object-reference to describe this, but he
correctly states that Python is call-by-value.)

Confusion over argument passing isn't limited to Python.  It's
remarkable how many programmers are convinced that although
call-by-value might explain argument passing in Pascal, their language
(Common Lisp, Scheme, C++, Python, etc.) must use some different
mechanism that those egghead computer scientists don't have a name
for.  This comes up so very often that sometimes I think understanding
argument passing might be the Pons Asinorum of Computer Science.




More information about the Python-list mailing list