💾 Archived View for yujiri.xyz › software › typing.gmi captured on 2023-07-10 at 13:33:25. Gemini links have been rewritten to link to archived content
View Raw
More Information
⬅️ Previous capture (2023-01-29)
➡️ Next capture (2023-09-08)
-=-=-=-=-=-=-
yujiri.xyz
Software
Subtle benefits of static typing
Everyone knows the main benefits of static typing: catching mistakes earlier so development is faster and fewer bugs get through, and better performance. But there are more subtle ones:
- *Better error messages.* In a dynamic language, not only do you have to run the program to find a type error, but when you do, the error usually won't point to the line that actually contains the mistake.
- *Code analyzers.* Linters and the like can never be very good in dynamic languages, because so much of the information necessary to determine what's a mistake isn't available until runtime. Dynamic languages use features like constructing types and changing what names are defined in a namespace at runtime. This places strict limits on how good static analyzers can be. Case in point: when I ran mypy on an old mini-CMS I'd written (the whole thing was like 1000 lines of code), it found 18 false positives and 0 true positives.
Mypy
- *Documentation*. Without type signatures, we have to document what a function expects in another way. Type signatures, since they're formal, are easier to parse (for the same reason bulleted lists make information easier to parse) and you can't forget to write them. I'm well acquainted with the frustation of reading a Python function's documentation that *just doesn't say* what it expects or returns.
contact
subscribe via RSS