General question about Python design goals

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Dec 1 08:34:58 CET 2005


Donn Cave <donn at drizzle.com> wrote:
> Tuples and lists really are intended to serve two fundamentally
> different purposes.
> [...]
> As I'm sure everyone still reading has already heard, the natural
> usage of a tuple is as a heterogenous sequence. [...] A list of
> command arguments is clearly homogeneous in this sense - any
> sequence of strings is a valid input, so any slice of this sequence
> must also be valid.  (Valid in the type sense, obviously the value
> and thus the result must change.)  A tuple of time values, though,
> must have exactly 9 elements, so it's heterogeneous in this sense,
> even though all the values are integer.
> 
> I have to confess that this wasn't obvious to me, either, at first,
> and in fact probably about half of my extant code is burdened with
> the idea that a tuple is a smart way to economize on the overhead of
> a list. Somewhere along the line, I guess about 5 years ago? maybe
> from reading about it here, I saw the light on this, and since then
> my code has gotten easier to read and more robust.

Strangely, I learned this as I was learning the language, and
understood it after reading the explanation a couple of times (I can't
remember where I was reading it, but it must have been a decent
guide).

However, in the intervening time I'd forgotten this fundamental
difference between the *purpose* of list and tuple.

Thanks very much for this reminder. You've probably stopped me from
writing a bunch of misguided code and realising 5 years too late :-)

-- 
 \       "Timid men prefer the calm of despotism to the boisterous sea |
  `\                                 of liberty."  -- Thomas Jefferson |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list