85 ms·
I tend to agree, Python really shines when it's just being Python. I only typehint certain parts of the code where i find it usefull. Typehinting everything ma
by kingofthehill98 3y ago
I tend to agree, Python really shines when it's just being Python.
I only typehint certain parts of the code where i find it usefull. Typehinting everything makes Python code really hard to read IMO.
- theLiminator 3y agoDefinitely disagree, especially not the case for function arguments. Having no types in the arguments makes an api incredibly hard to use.
- alanwreath 3y agoYou can slap out the POC without types for sure - but the addition of types helps - tests fail faster - code documentation - IDE’s complain better - teams collaborate better It becomes more helpful as projects and teams mature. I’d say that types aren’t the last step though, I’m starting to prefer protocols and those are proving to be even more loosely coupled and more pythonic to me. They let you “type” the behavior rather than the actual type. Say there is a case when you don’t care if it’s a set, tuple, or a list because all you’re going to do is Iterate, we’ll you’d go the behavior route and say you want an Iterator. You can create your own protocols as well and it has the effect that you document what you intend to do with the objects passed to you such that it doesn’t matter what you pass as long as it adheres to the protocol you defined. It’s documented duck typing. Here’s a great video that explains how it can simplify your code https://m.youtube.com/watch?v=xvb5hGLoK0A https://m.youtube.com/watch?v=xvb5hGLoK0A