Why use Perl when we've got Python?!

John W. Stevens jstevens at basho.fc.hp.com
Fri Aug 13 23:04:21 EDT 1999

> In comp.lang.perl.misc, 
>     "John W. Stevens" <jstevens at basho.fc.hp.com> writes:
> :> Instead, you need to remember to use
> :> 
> :>     a.append("delta")
> :
> :According to what you said earlier, this is better than the Perl
> :way.  Appending to a list is better, 'cause you can tell the
> :difference between adding a new element, vs. reassignment: two
> :different operations, right?
> Wrong.  I am merely sticking something at a particular place.
> If that place doesn't exist yet, MAKE IT SO.  Don't make 
> me check the length first.  

Your own reply indicates that these are two different operations.

In adding, you know you will not be overwriting and existing reference.

In assignment/reassignment, you don't.  When combining the two, you
are forced to add checks to determine the difference.

> :Excuse, but the two cases are different.  One is reassignment.  The
> :other is resize-list-and-add-a-new-element.  
> Don't be ludicrous.

I'm not.

FYI: I have consistently treated you with respect.  I ask only
     that you do the same.  However, this reply makes me wonder.
	 You know darn well that adding something to a container
     object is is different than putting something into an
     existing slot.

> I don't care whether something is there before.

Which goes a long way towards explaining some of those Perl
defects I was refering to in other replies. . .

> Are you telling me that python should have one syntax for
>     s = "original string"
> and then a different one for
>     s = "a new string that replaces the old one"

A variable is not a container class instance.  Your analogy is fatally

> It doesn't do that for dictionaries.

An acknowledged flaw in Python's orginal dictionaries, one which has
been partially solved on extraction through the addition of the get
method.  Insertion remains to be fixed, as there is some philosophical
disagreement as to the correct semantic.

> It shouldn't do so for lists.

Lists, by definition, do not have "empty", or non-existent slots, so
overloading assignment could violate the semantic of "list".  Append
is both simpler, and less error prone.

So I must strongly disagree.  The existing system is more correct.

John S.

More information about the Python-list mailing list