Typing system vs. Java

Christian Tanzer tanzer at swing.co.at
Thu Aug 2 12:27:47 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote:

> "Christian Tanzer" <tanzer at swing.co.at> wrote in message
> news:mailman.996682083.19421.python-list at python.org...
>     ...
> """
> > Back to Python -- programming in Python has always felt to
> > me a *LOT* like generic programming
> 
> Yup. Only, in Python it's very implicit.
> """
> ...just about as in C++, except more so:-).
> 
> 
> """
> The nice thing about Ada and Eiffel generics is that the requirements
> on the generic parameters are spellt out explicitly. For most
> """
> The problem with Ada and Eiffel generics is that the requirements
> on the generic parameters are to be spelled out explicitly.

The explicit spelling of the requirements has two consequences:

- It improves type checking. I agree that this doesn't cover a whole
  lot of ground (although Eiffel does a better job here than any other
  language, IMHO).

  I used to care a lot about static type checking but don't see this
  as a big issue anymore. 

- It improves reusability. In C++ or Python, you have to look at the
  source code of the generic component to know what the requirements
  are. In Ada or Eiffel, a look at the interface suffices. This is a
  big advantage over the implicit requirements.

  In Python that isn't so bad, because most often you can try it out
  in the interpreter just as fast as looking up the interface. In C++,
  trying it out and having the compiler barf out less than enlightened
  error messages is a royal pain.

Anyway, I'd love to have a type inference engine for Python code.

> But C++'s generics are an excellent example of the way lack of
> type-constraint declaration in no way inhibits type-based optimization
> -- given signature based polymorphism, type-inference in any actual
> instantiation of a generic IS pretty trivial:-).

C++ is very weak in optimizing template instantiations when compared
to Ada. That's probably not a feature of the language but a
shortcoming of the implementations. OTOH, after ten years templates
should be really trivial for the C++ compiler implementers. When I
looked last time (1998), the compilers were still pretty brain dead in
that regard, though.

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list