* Antoine Pitrou:
Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a écrit :
What Python does is called "pass by sharing", or sometimes "pass by
object reference". It is exactly the same as what (e.g.) Ruby and Java
do, except that confusingly the Ruby people call it "pass by reference"
and the Java people call it "pass by value", thus guaranteeing the
maximum amount of confusion possible.

Well, I think the Ruby people got it right. Python *does* pass parameters by reference. After all, we even speak about reference counting, reference cycles, etc.

So I'm not sure what distinction you're making here.

Steven talks about the standard meaning of "pass by reference".

Essentially that means that you can implement a routine "swap" such that

  a = 1; b = 2; swap( a, b )

results in a == 2 and b == 1.

In Pascal that's 'var' parameters, in C there's no such, in C++ it's reference type parameters using '&' as a type builder, in C# it's 'out' and 'ref' parameters (I think C# has both the most practical and the most elegant implementation, you can see at the call site whether it's by reference), so on.

To some degree "pass by reference" is however just a collection of special cases with some similarity. For example, if one says that the guiding principle & main criterion is that one should not have to indicate the pass by reference at the call site, then that would exclude C#. But if one allows some indication at the call site, then that would perhaps include C (applying the & address op), which everyone agrees does not have call by reference.

So, to understand the conventional meaning of the term it is perhaps necessary to have some knowledge of all the special cases, like here C# versus C.


Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to