Optional Static Typing
a at b.c
Thu Dec 23 17:09:28 CET 2004
bearophileHUGS at lycos.com wrote:
> Adding Optional Static Typing to Python looks like a quite complex
> thing, but useful too:
Thanks for pointing out that article by Guido van Rossum. Looks like it
just came out today. It is something that may be added to Python 3.0:
> Sometimes it can be useful to mix parts with static typing and parts
> without it in the same module (because dynamic typing is very useful
> sometimes), but some other times you want to be sure to have a full
> typed and checked module.
The closest option right now in CPython is to use Pyrex.
> Boo (http://boo.codehaus.org/) is a different language, but I like its
> "as" instead of ":" and "->", to have:
> def min(a as iterable(T)) as T:
> Instead of:
> def min(a: iterable(T)) -> T:
Right, you're first example is how Boo does it, and the 2nd is how Guido
proposed to do it in Python 3.0.
Boo flips the problem around. Instead of optional static typing,
everything is statically typed by default (but with type inference so
you do not always need to explicitly declare the type), and it has
optional runtime typing that works like python's ("duck typing").
And there are some disadvantages to doing it this way. It means Python
is more flexible to use than Boo, as I stated a couple months back:
More information about the Python-list