why python annoys me

Alex Martelli aleaxit at yahoo.com
Thu Apr 19 15:37:12 EDT 2001


"D-Man" <dsh8290 at rit.edu> wrote in message
news:mailman.987703709.17946.python-list at python.org...

    [snip: the Liskov Principle violation in 'covariant' mutable
collections]

> (Python) lists are much better (also with runtime lookups, rather than
> compile-time constant offsets) :-).

A Python list is more similar to a Java Vector -- it's not identical
because not all the Java equivalents of Python object do derive
from Object, but similar in that its design intent is to let you
stuff "anything" inside it, while an array is apparently meant
to be typesafe, by design intent (although it isn't, as we said,
under conditions of mutability).  Vectors and other collections
in current Java appear to be an explicit acknowledgment that
compile-time type checking doesn't match their use cases.

Parameterized-collections will presumably restore at least some
semblance of compile-time type checking.  I wonder whether
they'll keep trying to offer the apparently-natural 'covariance'
that Java arrays have, or, like C++'s templates, give up any
attempt at being either covariant or contravariant (you _could_
do the former for a collection that is passed as read-only and
the latter for one that is write-only, I believe, but I suspect
there is no way to capture even those limited possibilities in
Java's typesystem).  If I recall correctly, even Eiffel is neither
covariant or contravariant in parameterized types (although it
used to be [it's been too long since I checked whether the
language has been changed] covariant for parameters to
overridden methods, again breaching compile-time type safety
in favour of run-time checks).

The lack of any compile-time type-checks in Python saves
us from any such worry _currently_, but who knows what
the future holds in store.  Personally, I've always wondered
why most paladins of compile-time type-safety appear to
be unaware of such issues (back when I used to be such a
paladin myself, they'd keep me awake nights:-).


Alex






More information about the Python-list mailing list