terminological obscurity

Donn Cave donn at u.washington.edu
Tue May 25 12:03:29 EDT 2004


In article <1l25b0damv22nmja2na0i3k55e0p3jsef4 at 4ax.com>,
 Arthur <ajsiegel at optonline.com> wrote:
...
> Well for one, before new style classes, it was easier to think of an
> "instance" as in some sense a pseudo data type.  Instances of
> different classes - even with no hierarchical relationship - were more
> conceptually homogenous. 
> 
> But with everything subclassable,  2 different classes, each derived
> from object, are conceptually distinguished more similarly to the way
> in which a str and int are distinguished.

Really makes no difference at all - not just insignificant,
really _no_ difference.  A truly heterogeneous sequence may 
be full of references to the _same_ object (e.g., (1, 1, 1)),
and a truly homogeneous sequence may have objects as different
as None and a module.  It's not about properties of the objects,
considered in isolation.

>     GvR> I always think of the type of a list as "list of T" while I
>     GvR> think of a tuple's type as "tuple of length N with items of
>     GvR> types T1, T2, T3, ..., TN".  So [1, 2] and [1, 2, 3] are both
>     GvR> "list of int" (and "list of Number" and "list of Object", of
>     GvR> course) while ("hello", 42) is a "2-tuple with items str and
>     GvR> int" and (42, "hello", 3.14) is a "3-tuple with items int,
>     GvR> str, float".
> 
> He sort of stacks the cards by making his tuples of hetereogenous
> type, and his list easily described as a list of T. And thereby
> sidesteps all the ambiguities inherent in the ten word edict.  Except
> that at the Object level, we are at lists of Objects and tuples of
> Objects.  It detracts little from the point of the above quote, but
> this quote then becomes substantially weaker as support for his 10
> worder.

Guess he may have overestimated his audience.

If you're interested in the history of this matter, it may
help to know that Guido did not invent the tuple.  It has
been around in computer programming languages since Lisp.
You can actually find precisely parallel descriptions of
the concept in that context, down to the unnecessary use
of different data types to emphasize the heterogeneity.

Lisp and its relatives have both a tuple and a list type,
but the list is a `real list', not a 1-dimension array as
in Python but a recursive data structure.  In Python, this
data structure can be represented using a tuple:

  t = (0, None)
  t = (1, t)
  t = (2, t)
  ...
  def print_list(tail):
      value, tail = tail
      if tail:
          print_list(tail)
      print value

Guido's "mistake" is that unification of all these sequence
types leaves the distinctions less obvious.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list