[Python-Dev] re: syntax - "Aren't tuples redundant?"

gvwilson@nevex.com gvwilson@nevex.com
Fri, 4 Feb 2000 08:10:27 -0500 (EST)


(Hope no-one minds me keeping this thread alive --- as I said in my first
reply to Tim Peters, there's either something very fundamental here, or a
"just-so" story...)

> > > Tim Peters wrote:
> > > At heart, tuples are for Cartesian products of a fixed number of
> > > possibly differing types, while lists are for arbitrary-length
> > > sequences of a single type.

> > Greg Wilson wrote:
> > Fooey. Programmers raised on C, Fortran, Pascal, or Java would tell you
> > that the elements of [1, "two"] have different types.  So (I believe)
> > would most ten-year-olds, and they'd be right: I can't add 7 to "two", or
> > take a slice of 1. I can grandparent them by fiat with a type "any", but
> > that smells like I've decided what answer I want, and am now inventing
> > what I need to get there.

> Tim Peters wrote:
> The C++, Fortran, Pascal or Java programmer can't *spell* the list [1,
> "two"] in their languages without playing casting tricks.

Greg Wilson wrote:
The fact that their current language doesn't allow this is irrelevant to
the argument.  Show them [1, "two"] and they (a) understand it, and (b)  
think it's cool; show them (1, "two") as well and they become confused.

> Tim Peters wrote:
> Of course the elements are of different types, and for that very
> reason it's better to use a tuple here instead (especially if it's
> always of length two!).

Greg Wilson wrote:
But *why* is it better?  Or to put it another way:

    If tuples didn't already exist, would anyone ask for them to
    to be added to the language today?

> Tim Peters wrote:
> "Different data structures for different purposes" is as Pythonic as
> "different syntax for different purposes", and paying attention to
> this can improve your (that's the generic "your") Python programming
> life.

Greg Wilson wrote:
Analogic reasoning makes me nervous, as it is most often used to transfuse
legitimacy from the defensible to the suspect.

> Tim Peters wrote:
> Start from ground zero and try to explain why Python has both ints and
> floats:  there is no *obvious* reason (even less so for having both
> ints and longs, btw).

Greg Wilson wrote:
I've never had any trouble explaining int vs. float to students at any
level; I've also never had any trouble explaining int vs. long (memory vs.
accuracy).

Thanks for your reply,
Greg