Tuples -- who needs 'em

Bob Alexander bobalex at home.com
Mon Apr 3 11:24:08 EDT 2000


This is not an [intentional] flame bait, nor an April Fool's message, but
think about it: Python has two "sequence" data types, lists and tuples,
which from the Python programmer's perspective are only slightly different.
How does having both types significantly improve life for Python
programmers?

I can think of a few ways in which it makes life worse. Although I doubt
that having both types prevents anyone from mastering the language, it does
add some cognitive load in choosing whether to use a list or a tuple when a
sequence data type is needed. There are times when I started with the
"tuple" choice (since it's more "minimal" than list one should choose it
when one doesn't need the additional list features, right?) but later
changed it to list because I needed a list-type feature. Usually that would
be the need for mutability, but sometimes it's unrelated to mutability, like
wanting a method to search for a specific element (list.index()). (Can
someone tell me why index() and count() are not available for tuples?)

Even small reductions in cognitive load can yield significant benefits in
ease of use of a language.

Suppose Python had only one sequence data type: list, and that we could use
it in all places where tuples are needed now. I would never have to think
about whether to use tuple or list. I would never have to convert from tuple
to list or vice versa. Just one more thing I don't have to bother with.

I suspect there will be several answers offered as to why we need both
types, but I also suspect most of the benefits are for the Python
implementor(s), not programmers. Yes, there are probably a few times where
the ability to create an immutable sequence is useful, but is that enough to
warrant the additional complexity of a whole additional datatype? If
immutable sequences are so useful, then why not immutable mapping types,
etc. etc.?

Note that this message is coming from a Python fan, not a critic. This is
just an issue that has piqued my curiosity. Python is for the most part a
language where design choices have been in favor of ease of programming,
with few concessions to making life easier for language implementors. Having
both lists and tuples seems to be an exception.

-- Bob






More information about the Python-list mailing list