4 ms·
I could never get why Python added unchecked static typing. That seems so useless. If the compiler checks it, it can use it to optimize. Huge win for built-in t
by Animats 6y ago
I could never get why Python added unchecked static typing. That seems so useless. If the compiler checks it, it can use it to optimize. Huge win for built-in types, like integer and float. CPython has to box everything. PyPy has to try to guess and use just-in-time recompilation when it guesses wrong.
- neolog 6y agoFor now, it improves documentation and static typechecking. But Mypyc is an annotated-python-to-C compiler that's in the works.
- mfgs 6y agoType hints are super handy when using smart IDEs like PyCharm, which will list or highlight (most of) your type errors. This alone can greatly improve confidence in your program, especially for more complex cases. Getting that cheaply while still having types unchecked is a nice compromise between improved functionality and not changing the language majorly.
- kdmytro 6y agoUnchecked types by themselves are useful as they help my text editor to provide more accurate autocomplete suggestions.
- davesque 6y agoPython didn't add static typing. It added arbitrary annotations of arguments and variables (admittedly, with the use case of type checking in mind). Mypy uses that for type annotations and checking. Here are the two main reasons I think it's useful: * To the extent that it enables some static analysis on python code, it has often caught a number of errors I tend to make while writing code * It serves as a light form of documentation that tends to stay more fresh because there's an automated way to check its consistency (run the type checker) I don't expect that it will do as perfect a job as Rust or C++'s type system or even that it would be there for the same reasons. On the other hand, it's nice to just have more info about what the code is expected to do in the form of type annotations.
- dragonwriter 6y ago> Python didn’t add static typing. It added arbitrary annotations of arguments and variables (admittedly, with the use case of type checking in mind). Mypy uses that for type annotations and checking. Mypy started out as its own language with a Typescript-like relation to Python, evolved to being fully python compatible (using typing comments) after consultation with Guido (then-BDFL) and then python added annotations to support projects like mypy. It wasn’t just the that annotations were created and then mypy happened along to take advantage of them, supporting mypy specifically (without only supporting mypy) was a key motivation for annotations.