4 ms·
If type annotations are fully respected that programmers code it like a statically-typed language (no type change for a variable in scope), will it be possible
by riobard 16y ago
If type annotations are fully respected that programmers code it like a statically-typed language (no type change for a variable in scope), will it be possible to AOT compile it?
- rabidsnail 16y agoIn theory you should be able to AOT compile python now, with type inference. There are cases where the types are not inferable, as there are cases where the programmer does not provide type hints. But I think an approach similar to clojure's where types are inferred when possible, type hints can be provided optionally, and runtime reflection is used as a fallback when the type cannot be determined ahead of time is a good approach. You generally don't worry about types in clojure any more than you worry about types in python; you only add type hints in performance-sensitive code in cases where the compiler can't figure out the types on its own.
- andrewcooke 16y agoYou could, but it's not really worth it - you'd end up with a pretty boring language. Also, JITs (in particular PyPy) should be able to get decent performance in the near future without asking the programmer to do anything unusual. In simple terms they assume that types are whatever they find and compile for that (occasionally the assumption is wrong, and they have to correct and do something else, but most of the time you get good performance just by pretending the program was written with static types, even though it wasn't). Obviously it's more complex than that, but you get the idea (the hard part is largely reducing the number of times you need to check you're assumptions are still OK)