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

Tim Peters tim_one@email.msn.com
Fri, 4 Feb 2000 00:33:33 -0500


I'm fwd'ing this back to the list, because disagreement is more valuable to
share than agreement.

The C++, Fortran, Pascal or Java programmer can't *spell* the list [1,
"two"] in their languages without playing casting tricks.  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!).  "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.  I don't care if it's
not immediately obvious to new users (or even to you <wink>).   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).

Python wouldn't fall apart without tuples, but I'd miss them a lot (e.g., in
another vein, in an imperative language using immutable objects when
possible can greatly aid reasoning about code ("OK, they pass a tuple here,
so I don't have to worry at all about the callee mutating it") ...).

Python itself violates my "guidelines" in using a tuple to catch a vrbl
number of arguments, & I believe that's a minor design flaw (it should use a
list for this instead -- although you can't satisfy both "homogenous" &
"fixed length" at the same time here).

WRT Scheme, I don't believe it's a reasonable choice to teach newbies unless
they're CompSci majors; it would certainly be better if they had a language
that didn't need to be "layered".  DrScheme effectively *did* "re-design
their language" by introducing subsets.  Whether this is successful for
Mathias you'll have to argue with him; I don't see cause to believe SP/k is
relevant (neither the "subset" form of Fortran77 -- it was aiming at an
entirely different thing).


> -----Original Message-----
> From: gvwilson@nevex.com [mailto:gvwilson@nevex.com]
> Sent: Thursday, February 03, 2000 11:49 PM
> To: Tim Peters
> Subject: RE: [Python-Dev] re: syntax - "Aren't tuples redundant?"
>
>
> > 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 writes (to Tim Peters directly, in order to reduce bandwidth
> on the general list --- feel free to re-post there if you think there's
> any merit in what I've said below):
>
> 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.
>
> Footnote: every time someone's told me that a language has a "zen" that
> you have to "get", it's turned out that what they've really meant is that
> there's a set of "just-so" stories that you have to accept as gospel.  I
> really don't want to offend anyone, but the justifications I'm hearing for
> Python tuples are starting to sound like that.  I'd be very grateful if
> you could tell me what they actually buy programmers that lists don't,
> other than being usable as hash keys, and maintaining backward
> compatibility with earlier versions of Python.
>
> > BTW, despite the recent unpleasantness with the TeachScheme! folks,
> > there's a lot to be learned from DrScheme, part of which is the notion
> > of language "levels": the IDE can be set to restrict the newbie to
> > various (nested) subsets of the full language, so that new learners
> > are shielded from the hairier stuff until their confidence builds.
>
> I lived through another attempt to do this --- the SP/k series of layered
> languages based on PL/1.  It wasn't generally regarded as a success; when
> a Pascal compiler that generated readable error messages came along, SP/k
> was abandoned almost immediately.  No disrespect to Mathias and his
> colleagues, but I think that that if they have to shield learners from
> part of the language in order to make it learnable, they ought to
> re-design their language...
>
> Thanks,
> Greg