Type signature

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sat Jul 22 18:15:31 EDT 2006


In <mailman.8423.1153605052.27775.python-list at python.org>, Yacao Wang
wrote:

> However, type signatures are not only a kind of information provided for
> the compiler, but also for the programmer, or more important, for the
> programmer. Without it, we have to "infer" the return type or required
> agument types of a function, and this can't be done without seeing the
> implementation of it,

That's what documentation is meant for.  If you are forced to look at the
implementation, the documentation is bad.

> Haskell can also determine type information dynamically, but it still
> supports and recommends the programming style with type signatures,

Does Haskell really determine the type information dynamically!?  AFAIK
it's done at compile time.

> which makes the code very readable and maitainable. As I understand,
> Python relies too much on run-time type-checking, that is, whenever you
> give the wrong type, you just end up with an exception, which is
> logically correct, but not that useful as type signatures. Any ideas on
> this issue?

Which issue?  ;-)

Just stop thinking in terms of types.  Python is about *behavior*.  If
the docs say `this functions takes an iterable as input` then `iterable`
isn't a specific type but an object that implements the behavior of an
iterable.  You can't check that reliable without actually trying to
iterate over it.  Search for "duck typing".

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list