this post was submitted on 17 Aug 2024
713 points (95.4% liked)
Programmer Humor
32472 readers
806 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
But one compiling error is Java is 7 run time errors in python.
There is a type error and you couldn't have known it beforehand? Thanks for nothing
With type annotations, this problem is mostly alleviated in practice, while still keeping the productivity gains of duck typing.
In my experience, Python's type annotations are annoying as hell, because there's no inference.
You can use mypy and/or Pydantic.
Neither of those provide type inference? Type inference is when you give the compiler only occasional type hints and it can still figure out what the types are behind the scenes.
For example:
In a type-inferred language, the compiler would automatically know that:
Mypy on the other hand can only tell these things, if you give the first two lines an explicit type hint:
Having to do this on every line of code is extremely noisy and makes refactoring annoying. I can absolutely understand that Python folks think you get productivity gains from duck typing, if this is the version of static typing they're presented.
And we did excessively use mypy + type hints + pydantic on my most recent Python project. These are not the silver bullet you think they are...
If you're going to post a code example, at least check that it works. Here's your example, with no type hints, giving me errors both from the LSP, and when trying to run via mypy: https://imgur.com/a/Hq5Y5Gt.