3 ms·
as someone working in this space, the idea is that most python code is implicitly statically typed anyway, in that your functions are only ever meant to be call
by zem 2y ago
as someone working in this space, the idea is that most python code is implicitly statically typed anyway, in that your functions are only ever meant to be called with specific types for their arguments, and only return objects of a specific type. all that static type analysis does is to make that explicit via type annotations, and then verify that you have indeed used types correctly in your code. static compilers then say "well, if we know the static types of everything in this function, we can compile it to more efficient code, skipping all the dynamic lookups and runtime type checks and dispatching". typically there is an escape hatch that will fall back to regular python behaviour if your code is indeed dynamic (e.g. reflecting on a database schema to generate models at runtime), but losing the benefits of static analysis and optimisation.
if you would like to read more on the topic the keyword is "gradual typing"; in particular you might be interested in looking up stanza, a language designed around gradual types from the outset rather than retrofitting them on top of a dynamically typed language.
- agumonkey 2y agothis https://lbstanza.org/index.html https://lbstanza.org/index.html ? what are places to discuss gradual typing these days ? I stopped looking a few years ago (after clojure and scheme started projects on that topic)
- zem 2y agoyep, that's the one! I don't know if there's any one place to discuss gradual typing. typed racket is probably the language with the largest academic community behind it, so the racket discourse would likely have some good discussions, though I haven't been keeping up with it recently.
- agumonkey 2y agothanks a lot, i'll tag along the racketeers then, i was mostly curious to know if the field became wider, sometimes I get too focused on lisps and forget that other people are doing PLT
- bbkane 2y agoYou might also like Roc. I don't completely understand how but it does type inference over the whole program - so you can use a loose type that "tightens" when you use it in a different way. Maybe that's a bad explanation. I think the following video is the one that demonstrates this https://m.youtube.com/watch?v=7R204VUlzGc https://m.youtube.com/watch?v=7R204VUlzGc