Tuples -- who needs 'em

Bob Alexander bobalex at home.com
Thu Apr 6 11:14:30 EDT 2000

"Jonathan Giddy" <jon at dgs.monash.edu.au> wrote:

> I nearly fell out of my tree when Alexander, Bob declared:
> >I am wondering where the serious concern about mutable lists comes from,
> >it is a pattern in the responses I've gotten on this topic. For me, the
> >immutable list is a relatively new concept, since I can't think of many
> >other languages that have it. I'm a programming-language-design kind of
> >person, and I never really saw mutable lists as a problem that needed
> >solving.
> How about C?  Surely 'const' is an attempt to mark arrays as immutable.

Okay, that's true. Clearly my statement is exaggerated. Still, I can't
recall many instances where having only mutable sequences has caused me
trouble -- and this is over 30+ years of programming. And sometimes I pine
for the days before "const" was introduced  :-)

> Avoiding the x[i] = y construct is much harder in non-trivial programs,
> where assumptions about mutability need to be specified as part of the
> interface.  Hence the proliferation of const in the C string library.

Agreed -- any function that modifies a structure should spell that out
loudly in its interface description.

Programming languages make tradeoffs between easy coding vs. early error
detection. For example, the greater annotation required in C programs (e.g.
type declarations) makes coding harder, but allows detection of many errors
at compile time that would wait until run time in Python. In this case, the
distinction between tuples and lists is an "annotation" that allows us to
detect improper modification of a sequence earlier -- at the point of
attempted modification instead of later when it causes some other failure.
Most of Python opts for less annotation for easier coding vs. early error
detection -- having both mutable and immutable sequences is a move in the
other direction.

By the way, I personally prefer the low annotation level of Python-type
languages over C-type languages. It seems to me that programming is more
pleasant and overall the job gets done faster.

-- Bob

More information about the Python-list mailing list