4 ms·
> And to people about to mention types in python: those are also checked at runtime. They are not checked at runtime at all. Type declarations are only used fo
by cardanome 3y ago
> And to people about to mention types in python: those are also checked at runtime.
They are not checked at runtime at all. Type declarations are only used for static analyzing tools and not by the runtime.
So types are checked BEFORE runtime by the tooling just like they would be in TypeScript or any other language that offers gradual typing.
Yes, the dynamic nature of Python does make type safety and certain performance optimizations very difficult but then again it is the dynamic nature that allows for the high productivity of the language. A static language would be far less ergonomic to use for the typical prototyping and explorative programming done in Python.
- int_19h 3y ago> A static language would be far less ergonomic to use for the typical prototyping and explorative programming done in Python. A static language without type inference, sure. But that's not the only option. OCaml, for example, will infer object types for you based on what methods are called with what kinds of arguments inside the body.
- flakes 3y ago> They are not checked at runtime at all. Type declarations are only used for static analyzing tools and not by the runtime. This is the common usecase, but types certainly are used at runtime by many libraries. Frameworks like FastAPI use the type annotations to declare dependency injection which is resolved during application startup. In other cases like Pydantic, they are used to determine marshalling/unmarshalling strategies.