More random python observations from a perl programmer

Tim Peters tim_one at email.msn.com
Sat Aug 21 22:47:05 EDT 1999


Skipping most of this, since I already posted my own long reply to Tom.

[Tom Christiansen, admits <wink> that Perl copies arrays]

[Neil Schemenauer]
> What happens when you have a large array and pass it to a
> function?  This seems pretty inefficient.  If the array is not
> copied then why are they so many rules about when something is
> copied and when it is not.

The array gets copied.  In Perl4 there were tricks you could play with
symbol tables to avoid the copy, or you could rely on dynamic scoping and
not pass anything; in Perl5 there's a general notion of "reference type",
and you can avoid the copy by passing a reference to the array.  The callee
needs to know it's a reference, though (indexing a (de)reference to an array
requires different syntax than indexing an array directly; a huge (to me)
advantage of Python's uniformity is that the caller can choose to pass the
original array or a copy as it pleases, and the callee doesn't know the
difference).

>From a Python person's point of view, Perl *always* copies, and in the case
of passing a reference simply copies a small indirection object.  Python
never copies, but that's hard to explain to a Perl person because "no copy
== construct a reference" to them, while that way of viewing it makes little
sense to a Python person.

there's-no-way-to-break-out-of-this<wink>ly y'rs  - tim






More information about the Python-list mailing list