Ted Leung on the air
Ted Leung on the air: Open Source, Java, Python, and ...
Ted Leung on the air: Open Source, Java, Python, and ...
Wed, 05 Nov 2003
Why type annotation is important for Python
James Robertson
didn't like my idea for a Python type annotator as a MS thesis level Python project. I happen to agree with James' opinion on the value of testing vis a vis discovering type errors. The reason that I think a type annotator is important is that it can be provided as a crutch for those who are used to static typing and are just too afraid to let it go. Once you have a type annotator, it becomes a matter of time before you can demonstrate that programs that pass your test suites also pass the type annotator. Once that becomes routine, you can stop running the annotator. This one is about doing something to get the curly brace people to jump the fence and come on over.
If an annotator makes it easier to geneate IDL or WSDL or whatever, then that's a nice side effect as well.
[23:24] |
[computers/programming/python] |
# |
TB |
F |
G |
5 Comments |
Thanks for continuing this dialog. I can't find the source for GvR's quote in this weeks Python-URL but your thoughts on this would be appreciated.
"...at some point in the future Python will grow (optional) type declarations for all sorts of things (arguments, local variables,instanc e variables)."
--Guido van Rossum
(p.s. Congrats on OSAF! :-))
Posted by DeanG at Thu Nov 6 08:17:31 2003
"...at some point in the future Python will grow (optional) type declarations for all sorts of things (arguments, local variables,instanc e variables)."
--Guido van Rossum
(p.s. Congrats on OSAF! :-))
Posted by DeanG at Thu Nov 6 08:17:31 2003
I don't know... that argument doesn't do much to convince me at all.
I already hate (hate hate hate) double-underscore, which seems like another holdover from other B&D-style languages. People bring that style from previous (mis-) education, and typically from proprietary environments where there's lots of mutual distrust, maybe due to opacity among other things. It is not in the Python community's best interest to provide these kind of crutches for new programmers, because in using these crutches they exclude the community and exclude themselves from the community. Type annotation seems like the same issue.
That said, I can see some use for type annotation used strictly in a local scope, for the inner loops that often are most in need of optimization. Here the annotations don't exclude anyone.
But I'd hate to see type annotation in interfaces, because it's just so very, very wrong to do that. Pre-conditions and post-conditions are good, interfaces are good, adaptation is good, abbreviated ways of expressing the most common patterns of these conditions are good. Type annotation is just one small, restrictive, and unhelpful subset of the possible combination of these more general rules.
Posted by Ian Bicking at Thu Nov 6 08:41:32 2003
I already hate (hate hate hate) double-underscore, which seems like another holdover from other B&D-style languages. People bring that style from previous (mis-) education, and typically from proprietary environments where there's lots of mutual distrust, maybe due to opacity among other things. It is not in the Python community's best interest to provide these kind of crutches for new programmers, because in using these crutches they exclude the community and exclude themselves from the community. Type annotation seems like the same issue.
That said, I can see some use for type annotation used strictly in a local scope, for the inner loops that often are most in need of optimization. Here the annotations don't exclude anyone.
But I'd hate to see type annotation in interfaces, because it's just so very, very wrong to do that. Pre-conditions and post-conditions are good, interfaces are good, adaptation is good, abbreviated ways of expressing the most common patterns of these conditions are good. Type annotation is just one small, restrictive, and unhelpful subset of the possible combination of these more general rules.
Posted by Ian Bicking at Thu Nov 6 08:41:32 2003
Ian,
I'm not proposing that the annotations be left in the Python code, merely that the annotator be able to verify that a piece of code type-checks. Think of it as pychecker for types.
I'd like to see more people start using languages like Python, and for some of them, a tool like this will help. They may not ever us it, but they can go to their management and say "we ran it through the type checker and it's okay".
OTOH, if Guido is really serious about optional type declarations, then maybe this is all moot.
Posted by Ted Leung at Thu Nov 6 10:13:43 2003
I'm not proposing that the annotations be left in the Python code, merely that the annotator be able to verify that a piece of code type-checks. Think of it as pychecker for types.
I'd like to see more people start using languages like Python, and for some of them, a tool like this will help. They may not ever us it, but they can go to their management and say "we ran it through the type checker and it's okay".
OTOH, if Guido is really serious about optional type declarations, then maybe this is all moot.
Posted by Ted Leung at Thu Nov 6 10:13:43 2003
PyPy is to have type-inference and an internal annotation system to go along with it. It would be cool if the system was able to give interactive feedback and generate reports based on that information.
Posted by Robert Sayre at Thu Nov 6 15:35:28 2003
Posted by Robert Sayre at Thu Nov 6 15:35:28 2003
I don't really buy the crutch argument. Optional static typing, be it inferred through runtime analysis, static analysis or explicitly; it could enable so many other advances for python that the new convert argument would be at the bottom of my list.
The possibilities include:
* Automatic code generation to interact with statically typed languages. This could happen either during a compilation phase or during a JIT. This would be like building in ctypes and Pyrex directly into the language. I would be extra happy if the type inference was done OCaml style.
* Automatic code generation for performance, see below
* Hints to PyPy
* Making it easier to implement run time type enforcement rather than coding it by hand.
* Could enable the multilanguage VM where Python, Java and OCaml could execute side by side, ala Jython
I personally would frown upon using static typing in interface definitions except in some narrow circumstances such as interfacing native code or performance critical libraries such a Numeric. Python is good because it is generic.
Typing could be bad for the following reasons:
* Could force developers to create an abundance of unneeded wrapper classes
* We could see types start to leak out from interfaces and infect the rest of the calling code.
* Needs to be thoroughly thought out, the implications of a poor design could make Python a lot less fun. Maybe it needs a way to turn it off and revert all of the typed code back into plain python ?
Posted by Sean Jensen-Grey at Sat Nov 15 00:33:05 2003
The possibilities include:
* Automatic code generation to interact with statically typed languages. This could happen either during a compilation phase or during a JIT. This would be like building in ctypes and Pyrex directly into the language. I would be extra happy if the type inference was done OCaml style.
* Automatic code generation for performance, see below
* Hints to PyPy
* Making it easier to implement run time type enforcement rather than coding it by hand.
* Could enable the multilanguage VM where Python, Java and OCaml could execute side by side, ala Jython
I personally would frown upon using static typing in interface definitions except in some narrow circumstances such as interfacing native code or performance critical libraries such a Numeric. Python is good because it is generic.
Typing could be bad for the following reasons:
* Could force developers to create an abundance of unneeded wrapper classes
* We could see types start to leak out from interfaces and infect the rest of the calling code.
* Needs to be thoroughly thought out, the implications of a poor design could make Python a lot less fun. Maybe it needs a way to turn it off and revert all of the typed code back into plain python ?
Posted by Sean Jensen-Grey at Sat Nov 15 00:33:05 2003
You can subscribe to an RSS feed of the comments for this blog:
Add a comment here:
You can use some HTML tags in the comment text:
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk
To insert a URI, just type it -- no need to write an anchor tag.
Allowable html tags are:
<a href>
, <em>
, <i>
, <b>
, <blockquote>
, <br/>
, <p>
, <code>
, <pre>
, <cite>
, <sub>
and <sup>
.You can also use some Wiki style:
URI => [uri title]
<em> => _emphasized text_
<b> => *bold text*
Ordered list => consecutive lines starting spaces and an asterisk