[Python-Dev] Re: lists v. tuples

Just van Rossum just@letterror.com
Fri, 14 Mar 2003 17:06:14 +0100


Christian Tismer wrote:

> And the key assumption for sorting things is that
> the things are sortable, which means there
> exists and order on the basic set.
> Which again suggests that list elements usually
> have something in common.

To me it suggests that some lists are sortable and others are not...

There's one aspect about this discussion that I haven't seen mentioned
yet: syntax. I think the suggested usages of lists vs. tuples has more
to do with list vs. tuple _syntax_, and less with mutability. From this
perspective it is natural that tuples support a different set of methods
than lists. However, mutable vs. immutable has it's uses also, and from
_that_ perspective it is far less understandable that tuples lack
certain methods.

FWIW, I quite like the way how the core classes in Cocoa/NextStep are
designed. For each container-ish object there's a mutable an immutable
variant, where the mutable variant is usually a subclass of the
immutable one. Examples:
  NSString -> NSMutableString
  NSData -> NSMutableData
  NSArray -> NSMutableArray
  NSDictionary -> NSMutableDictionary

(But then again, Objective-C doesn't have syntax support for lists _or_
tuples...)

Just