PEP 3107 and stronger typing (note: probably a newbie question)

Paul Rubin http
Sun Jul 8 01:41:21 EDT 2007


Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> writes:
> > Some users in fact recommend writing an explicit type signature for
> > every Haskell function, which functions sort of like a unit test.
> 
> Stop here. explicit type signature == declarative static typing !=
> unit test.

The user-written signature is not a declaration that informs the
compiler of the type.  The compiler still figures out the type by
inference, just as if the signature wasn't there.  The user-written
signature is more like an assertion about what type the compiler will
infer.  If the assertion is wrong, the compiler signals an error.  In
that sense it's like a unit test; it makes sure the function does what
the user expects.

> I have few "surprises" with typing in Python. Very few. Compared to
> the flexibility and simplicity gained from a dynamism that couldn't
> work with static typing - even using type inference -, I don't see it
> a such a wonderful gain. At least in my day to day work.

I'm going to keep an eye out for it in my day-to-day coding but I'm
not so convinced that I'm gaining much from Python's dynamism.
However, that may be a self-fulfilling prophecy since maybe I'm
cultivating a coding style that doesn't use the dynamism, and I could
be doing things differently.  I do find since switching to Python 2.5
and using iterators more extensively, I use the class/object features
a lot less.  Data that I would have put into instance attributes on
objects that get passed from one function to another, instead become
local variables in functions that get run over sequences, etc.



More information about the Python-list mailing list