7 ms·
I really love Python for it's expedience, but type hints still feel like they don't belong in the language. They don't seem to come with the benefits of optimis
by circadian 1y ago
I really love Python for it's expedience, but type hints still feel like they don't belong in the language. They don't seem to come with the benefits of optimisation that you get with static typed languages. As someone who uses C and Julia (and wishes they had time for Rust), introducing solid typing yields better end results at a minimum, or is a requirement at the other end of the scale.
The extra typing clarification in python makes the code harder to read. I liked python because it was easy to do something quickly and without that cognitive overhead. Type hints, and they feel like they're just hints, don't yield enough of a benefit for me to really embrace them yet.
Perhaps that's just because I don't use advanced features of IDEs. But then I am getting old :P
EDIT: also, this massively depends on what you're doing with the language! I don't have huge customer workloads to consider any longer..!
- imron 1y ago> I don't use advanced features of IDEs I use vanilla vim (no plugins) for my editor, and still consider type hints essential.
- zahlman 1y ago> They don't seem to come with the benefits of optimisation that you get with static typed languages They don't. And cannot, for compatibility reasons. Aside from setting some dunders on certain objects (which are entirely irrelevant unless you're doing some crazy metaprogramming thing), type annotations have no effect on the code at runtime. The Python runtime will happily bytecode-compile and execute code with incorrect type annotations, and a type-checking tool really can't do anything to prevent that.
- afiori 1y agoNow that python has a jit it could use them (not saying it should) for speculative compilation My understanding is that currently python can collect type data in test runs and use it to inform the jit during following executions
- zahlman 1y ago> Now that python has a jit it could use them (not saying it should) for speculative compilation I'd forgotten about that. Now that you mention it, my understanding is that this is actually the plan.
- xdfgh1112 1y agoThey catch bugs. And you don't have to use them; even if they're only provided by libraries, there is a benefit to users.
- stellalo 1y ago> The extra typing clarification in python makes the code harder to read It’s funny, because for me is quite the opposite: I find myself reading Python more easily when there are type annotations. One caveat might be: for that to happen, I need to know that type checking is also in place, or else my brain dismissed annotations in that they could just be noise. I guess this is why in Julia or Rust or C you have this stronger feeling that types are looking after you.
- circadian 1y agoI think the face they fundamentally don't look after you is where my resistance comes from. Will try and evaluate some newer code that uses them and see how I get on a bit more :)
- Ekaros 1y agoRemembering project where type hints would have been helpful to grok the code I do now mostly like them. They are useful when you come back after days or weeks and try to remember what does this function produce and what does this one actually take in. And Python always was rather strongly typed, so you anyway had to consider the types. Now you get notes. Which often do help.
- IshKebab 1y ago> The extra typing clarification in python makes the code harder to read. It depends what you mean by "read". If you literally mean you're doing a weird Python poetry night then sure they're sort of "extra stuff" that gets in the way of your reading of `fib`. But most people think of "reading code" and reading and understanding code, and in that case they definitely make it easier.
- tdeck 1y ago'Twas brillig: Adjective and the slithy toves: Noun Did gyre: Verb and gimble: Verb in the wabe: Noun
- Izkata 1y agoAs someone who has read code as easily as English for decades (which is apparently rare, if my co-workers are any indication), too many type annotations clutter it up and make it a lot harder to read. And this is after having used Typescript a lot in the past year and liking that system - it works well because so much can be inferred.
- IshKebab 1y agoPython also has type inference. I don't think it really has more type annotation "noise" than Typescript does.
- ratmeadow 1y agoInteresting that for you typing makes the code harder to read. What context do you use Python for? And who is writing it? In my experience I have seen far too much Python code like `def func(data, args, *kwargs)` with no documentation and I have no clue wtf it's doing. Now I am basically all in on type hints (except cases where it's impossible like pandas).