list vs tuple

Carlos Alberto Reis Ribeiro cribeiro at mail.inet.com.br
Sat Mar 31 09:35:37 EST 2001


At 10:01 31/03/01 +0000, deadmeat wrote:
>What python DOES is irrelevant - the way it's written (and therefore viewed
>by programmers coming from other languages) makes it inconsistant.  The same
>statement (a = b) behaves entirely differently in each case.

I also came from a Pascal background (I used UCSB Pascal 15 years ago, and 
Turbo Pascal 1.0 (!) :-P), and I can tell you that this is not exactly true 
for Pascal either.

Using "pure" Pascal, an assignment is expected to copy the value from the 
right side to the left side. There is a number of catches, however:

- The copy operation can be expensive if the variable is a large object.
- Stack space is a concern. Copying large parameters take up a lot of stack 
space. There were some limitations on the return types accepted in older 
version of Pascal because of this also.
- There is an difference between "copy" and "deep copy". What happens if 
you make copy a structure that contains pointers in it? The pointers 
themselves are copied, but the "pointed" copy is still the same. As you 
don't have garbage collection or ref count, it's up to you to manage the 
situation to avoid freeing memory space while some copy of your structure 
is still pointing to the original memory area.

In Delphi, and also in other variants of Object Pascal, you have classes, 
and that changes everything. Class instances are always references, in a 
way very similar to Python classes. So if you do the following in Delphi, 
what do you get?

   a := TStringList.Create;
   b := a;
   a.Add('One line');
   /* b now contains the same line added to A */

As you may see, reference copy is everywhere - even inside Pascal :-)


Carlos Ribeiro









More information about the Python-list mailing list