Type Hinting vs Type Checking and Preconditions
Scott David Daniels
scott.daniels at acm.org
Wed Mar 8 10:43:09 EST 2006
Tom Bradford wrote:
> Really what we're talking about here is weak typing in the form of
> optional type hinting performed on a function by function basis....
Not what most of the world calls weak typing.
> It is my feeling that this doesn't represent a sea-change in the way
> Python does things, and it's certainly *not* the way things are done in
> Java or C++, as both of those languages are strongly typed, wherein you
> can't even pass a parameter if it isn't of the expected type, or a
> subclass thereof.
But I would call both of those languages weakly typed (and Python
strongly typed).
Any _correct_ type system must have contra-variant typing on results and
co-variant typing on values.
Java's type system breaks because it has decided to have arrays (which
are both in and out, therefore "pinned" as to type) obey the subtype
relationship of the elements of that array.
So:
array of truck-driver
is a subtype of:
array of driver
and a procedure:
procedure stores(driver[] arr, driver gus)
arr[1] = gus
Will type check as type-correct when passed a taxi-cab driver.
I suspect such problems can be found in C++ as well, but I never
hunted very hard.
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list