General question about Python design goals

Antoon Pardon apardon at forel.vub.ac.be
Thu Dec 1 05:11:56 EST 2005


On 2005-12-01, Donn Cave <donn at drizzle.com> wrote:
> Quoth bonono at gmail.com:
>| Christoph Zwerschke wrote:
> ...
>|> Sorry, but I still do not get it. Why is it a feature if I cannot count
>|> or find items in tuples? Why is it bad program style if I do this? So
>|> far I haven't got any reasonable explanation and I think there is no.
>|
>| I have no idea, I can understand their view, not necessarily agree. And
>| reasonable explanation is not something I usually find on this group,
>| for issues like this.
>
> It's hard to tell from this how well you do understand it, and of
> course it's hard to believe another explanation is going to make
> any difference to those who are basically committed to the opposing
> point of view.  But what the hell.
>
> Tuples and lists really are intended to serve two fundamentally different
> purposes.  We might guess that just from the fact that both are included
> in Python, in fact we hear it from Guido van Rossum, and one might add
> that other languages also make this distinction (more clearly than Python.)
>
> As I'm sure everyone still reading has already heard, the natural usage
> of a tuple is as a heterogenous sequence.  I would like to explain this
> using the concept of an "application type", by which I mean the set of
> values that would be valid when applied to a particular context.  For
> example, os.spawnv() takes as one of its arguments a list of command
> arguments, time.mktime() takes a tuple of time values.  A homogeneous
> sequence is one where  a  and  a[x:y]  (where x:y is not 0:-1)  have
> the same application type.  A list of command arguments is clearly
> homogeneous in this sense - any sequence of strings is a valid input,
> so any slice of this sequence must also be valid.  (Valid in the type
> sense, obviously the value and thus the result must change.)  A tuple
> of time values, though, must have exactly 9 elements, so it's heterogeneous
> in this sense, even though all the values are integer.
>
> One doesn't count elements in this kind of a tuple, because it's presumed
> to have a natural predefined number of elements.  One doesn't search for
> values in this kind of a tuple, because the occurrence of a value has
> meaning only in conjunction with its location, e.g., t[4] is how many
> minutes past the hour, but t[5] is how many seconds, etc.

I don't agree with this. Something can be a hetergenous sequence, but
the order can be arbitrary, so that any order of the elements can work
as long as at is well defined beforehand. Points on a 2D latice are
by convention notated as (x,y) but (y,x) works just as well. When
working in such a lattice it is possible to be interested in those
points that lay on one of the axes. Since the X-axis and the Y-axis
play a symmetrical role, it is possible that it doesn't matter which
axis the point is on. So counting how many of the coordinates are
zero is natural way to check if a point is on an axe. Doing a find
is a natural way to check if a point is on an axis and at the same
time find out which one.

So that a sequence is heterogenous in this sense doesn't imply
that count, find and other methods of such kind don't make sense.

-- 
Antoon Pardon



More information about the Python-list mailing list