tag:blogger.com,1999:blog-5135517.post110425767715234375..comments2023-11-05T03:54:44.710-08:00Comments on Making it stick.: The ROI of Optional Type AnnotationsPatrick Loganhttp://www.blogger.com/profile/02088461489050417591noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-5135517.post-1104438439441683242004-12-30T12:27:00.000-08:002004-12-30T12:27:00.000-08:00"""Also, I don't like them so much, but look at PE..."""Also, I don't like them so much, but look at PEAK's generic functions for another take on this,"""<br /><br />I've looked; in fact I wrote them. :)<br /><br />Seriously, for simple type-based dispatch, an inline way of specifying type or interface would be quite nice for generic functions.<br /><br />My point is that I'd like to be able to introspect on argument type -- from *outside* the function. For example, if arguments had type data available via 'inspect.getargspec()', then I could do something like:<br /><br />@somegeneric.when()<br />def something(x:int, y:str):<br /><br />instead of the current:<br /><br />@somegeneric.when("x in int and y in str")<br />def something(x,y):<br /><br />As I said, I don't care if the syntax is pure documentation, as long as it's introspectable.<br /><br />Another interesting use is that one could have a metaclass that inspected the constructor's argument types to define a relational schema for that class... Anyway, there are zillions of applications (imo) for being able to annotate arguments as well as functions. I personally don't want to see 'def foo(x@int,y@str)', though!<br /><br />I might go for a style like 'def foo(x [int], y [str])' though, as that would help emphasize the optional and descriptive (as opposed to restrictive!) nature.PJEhttps://www.blogger.com/profile/04688223805457202941noreply@blogger.comtag:blogger.com,1999:blog-5135517.post-1104330247260342562004-12-29T06:24:00.000-08:002004-12-29T06:24:00.000-08:00In none of the dialogue on this topic have I heard...In none of the dialogue on this topic have I heard <A HREF="http://www.blogger.com/r?http%3A%2F%2Fboost.org%2Flibs%2Fpython%2Fdoc%2Findex.html">boost::python</A> mentioned.<br />Why not let just migrate the application pieces that would benefit from C++ification migrate gacefully into boost::python, and resist the temptation to 'sex up' what is truly a beautiful product?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5135517.post-1104273808920027572004-12-28T14:43:00.000-08:002004-12-28T14:43:00.000-08:00There *are* other uses for type declarations besid...There *are* other uses for type declarations besides type checking. For example, the Naked Objects framework in Java uses method signatures to figure out what actions might apply when one object is dragged-and-dropped onto another object in a GUI.<br /><br />Documentation, of course, is an even more immediately useful use case. A good syntax would be more precise and more brief than docstring explanations. And, such information can be cross-referenced -- if you're looking at a method that takes an IFoo, it's nice to be able to jump to the documentation for IFoo.<br /><br />Last, but far from least, declarations are useful in interfacing to code built in languages that have declarations. Interfacing to C, Objective-C, C++, C#, and Java would all be much easier if type declarations were available -- even if the Python language itself had no semantics for such declarations!<br /><br />In other words, what I'm saying is that declarations could be a purely syntactic/metadata feature, and they'd still be quite useful for many things.<br /><br />Note, by the way, that people have interfaced to those other languages with Python already, but the APIs can be quite awkward because there's no simple way to argument/return/attribute metadata. So, having such annotations would be an immediate win for those interface tools. An important part of Python's heritage and future is that it is "universal glue" -- it doesn't shy away from talking with other languages, whether those languages are static or dynamic.<br /><br />Is there a danger of over-declaration by newbies? Sure. I'd probably find it really annoying to use code with excessive declarations, if those declarations actually restricted anything. However, if they were *just annotations* (or were adaptation specifiers per PEP 246), then I could still pass their code any darn thing I pleased, and we could all continue to be happy.PJEhttps://www.blogger.com/profile/04688223805457202941noreply@blogger.com