this post was submitted on 30 Jan 2025
309 points (97.5% liked)
Programmer Humor
20265 readers
1788 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Python 3.x will never have static typing because that would break backwards compatibility.
However, typing hints have been Integrated into Python for a while, and you are heavily recommended to use them, so your IDE can enforce typing.
Also have the option of selectively/strictly enforcing in CI, to get an experience & protections similar to "compile-time type checking"
Considering there is typing in the code why is there no switch to enable type checking at runtime? PHP does this with a per file
declare(strict_types)
- why would python be unable to have either a global or per file flag to enable checks?Have you got problems this would solve? I've done a lot of type annotated Python at scale and I can't think of an example.
Edit: given nobody in their right mind allows code that's not checker clean.
Typing when you need it gives you more freedom over a toggle. You can choose to type some parts of the code while leaving other parts untyped.
For example, if I'm writing a quick and simple Python script I may forgo typing, but when iterating on it I'd go back and add the types I need.
This isn't an issue, though. PHP has the same partial typing flexibility. There are ways to solve that issue and even typed PHP still allows union types including
mixed
which allows any types.