PEP 3107 and stronger typing (note: probably a newbie question)
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Jul 9 18:06:09 CEST 2007
Paul Rubin a écrit :
> 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.
It still boils down to the same problem : possibly valid types are
rejected based on a declaration.
>> 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.
I sure do.
> However, that may be a self-fulfilling prophecy since maybe I'm
> cultivating a coding style that doesn't use the dynamism,
Perhaps is this coding style not making the best use of Python's
features ? To me, it sounds like doing procedural programming in OCaml -
it's of course possible, but probably not the best way to use the language.
> 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.
Dynamism is more than simply adding "cargo" attributes to objects.
More information about the Python-list