4 ms·
100% agree - never really understood the movement behind adding types to Python. Type hints are a useless complexity that yield little return. If you want types
by jonathan-adly 4y ago
100% agree - never really understood the movement behind adding types to Python. Type hints are a useless complexity that yield little return. If you want types, use something else other than Python. The whole thesis behind Python is simple is better than complex.
- mjr00 4y agoHow is "this function takes a string and returns a float" more complex than "this function takes any data type and returns an unspecified data type"?
- Inityx 4y agoOn the one hand yeah, I agree with this, but on the other hand you have a lot of enormous software projects written in Python that are decidedly not simple, and would be extremely difficult to completely rewrite in a different language. Type hints do offer some value in this circumstance, by making it easier for disparate groups to modify the same large codebase though static analysis.
- bobbylarrybobby 4y agoThey're great for autocomplete, but that's pretty much it
- forrestthewoods 4y ago> If you want types, use something else other than Python. Python is still strongly typed. Me: what type does this argument need to be? Python: you have to figure that out Me: I just pass whatever I want? Python: Oh no. Usually only a single specific type is supported. But you have to guess what it is. Me: what if I get it wrong? Python: the program crashes at runtime
- lifewallet_dev 4y agoYou don't understand what "strongly typed" means... I give you a hint, `"1" == 1` is a type error in Python but "okay" in JavaScript because this one is "weakly typed", you're confusing "dynamic typing vs static typing" with "strongly typed vs weakly typed".
- forrestthewoods 4y agoPython is a strongly, dynamically typed language. Most Python type errors could be caught by a static analyzer. If Pythons type hint system wasn’t a disappointment it would help more people catch more bugs when they’re written. Instead Python endlessly throws exceptions at runtime because a programmer got their types wrong. Thanks for the hint.
- sirsinsalot 4y agoI find it best to see type hinting as "living documentation". Yeah, you can ignore it, it is Python afterall, but if you want the IDE/tools to have better more helpful hints ... use machine readable hint documentation. I'd argue if your functions are full of type-assert like guards, _then_ use another language!
- bb88 4y agoI just saw someone on Twitter post a "IntegerType" class which did exactly this, including capturing the sign -- because he couldn't trust int().
- retrac 4y ago> useless complexity that yield little return Typechecking allows certain errors to be detected at typecheck time rather than at runtime. I don't personally consider that useless. E.g. A mistake I just made. I'm working in a language I don't know too well right now with strict static typing. The file read function takes a handle. If I pass it a string of the file name, rather than the handle result from file open, it just doesn't compile. In most dynamic languages, that error would not be detected until it executes.
- ReflectedImage 4y agoThe changes you need to make to a Python program to enable it to be type checked result in more bugs being added than the type checker removes leaving you at a net negative. Type checking is just a really poor way to ensure program correctness until you start using an exceptionally strongly typed language like Haskell. You use types in C / C++ / Java because the compiler needs them to work not because it's a good idea.
- mjr00 4y ago> The changes you need to make to a Python program to enable it to be type checked result in more bugs being added than the type checker removes leaving you at a net negative. This claim doesn't make sense to me. Assuming mypy is regularly run as part of CI, why would adding type annotations cause more bugs than leaving it off?