Optional Static Typing

Doug Holton a at b.c
Thu Dec 23 11:09:28 EST 2004


bearophileHUGS at lycos.com wrote:
> Adding Optional Static Typing to Python looks like a quite complex
> thing, but useful too:
> http://www.artima.com/weblogs/viewpost.jsp?thread=85551

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:
http://www.python.org/moin/Python3.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.
http://nz.cosc.canterbury.ac.nz/~greg/python/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").
http://svn.boo.codehaus.org/trunk/tests/testcases/integration/duck-2.boo?view=auto
http://svn.boo.codehaus.org/trunk/examples/duck-typing/XmlObject.boo?view=auto
http://svn.boo.codehaus.org/trunk/tests/testcases/integration/duck-5.boo?view=auto
http://boo.codehaus.org/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:
http://groups-beta.google.com/group/comp.lang.python/messages/c57cf0e48827f3de,a750c109b8ee57c3,cf89205a5e93051e,cfb1c7453e1f3c07,58a2dedd1059783e,8a1ee82cc328d023,7a51cdc9ffecbc72,38304f35cb42bb63,fc5e4ae1cbae0248,2de118caa7010b30?thread_id=5a7018d37b7bf4b8&mode=thread&noheader=1&q=boo+python-like#doc_7a51cdc9ffecbc72



More information about the Python-list mailing list