[Python-Dev] re: syntax - "Aren't tuples redundant?"
Guido van Rossum
guido@python.org
Thu, 03 Feb 2000 16:20:29 -0500
> > > 4. "Aren't tuples redundant?"
>
> > To my mind, the "can act as dictionary key" argument is a red
> > herring. Tuples and lists may technically be almost the same
> > thing, but I find I hardly ever need to ponder whether I should
> > use a tuple or a list. Tuples are structures and lists are
> > containers.
>
> They're not structures the way a C programmer thinks of a struct or a pascal
> programmer thinks of a record.
That doesn't matter; I'd like to assume that we want to teach students
who don't already have a preconceived notion of a Pascal record or C
struct.
> Do you have a better way of justifying their existence to novices who
> haven't reached the zen? It's a nontrivial pedagogical problem in my
> experience as well. (yes, this is a better topic for edu-sig than for
> python-dev).
I have a feeling that introducing optional static typing would help
here, because it clarifies the concept. For example, these two have
the same type, [int]: (the length is part of the value)
[3, 100]
[5, 6, 7]
On the other hand, these two have different types:
(3, 100) # (int, int)
(5, 6, 7) # (int, int, int)
If we start mixing types, we may get
[3, "wow"] # [any]; or perhaps [int|str]
(3, "wow") # (int, str)
We can then explain that we might have informal names for the parts,
and we can use these as local variable names. This is borrowed
from ABC, which did at least *some* user testing on issues like this:
count, value = t
t = count, value
(ABC used a different assignment syntax; it would be:
PUT t IN count, value
PUT count, value IN t
I am still friends with the librarian who was taught ABC as a guinea
pig.)
However, ABC was a statically typed language in the sense of Haskell:
there were no declarations but the types were inferenced from
initializations and operators. Maybe that *does* make a difference.
Also, its tuples were completely unlike sequences: they didn't have
indexing or slicing. There were no tuples of lengths 1 or 0.
--Guido van Rossum (home page: http://www.python.org/~guido/)