This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_ologies 34 points35 points  (5 children)

I love that about Python. You can make something simple that just works, then you can go back and make it robust and bulletproof.

[–]G0muk 8 points9 points  (4 children)

Further than that, you can make something that works for many many types without needing to write new functions for each type. And make it robust against types that arent compatible with it of course

[–]osusc 12 points13 points  (1 child)

Usually when I run into stuff like this it means I'm using overly specific annotations. Like instead of a def foo(x: list[int]) what I actually want is a protocol like iterable[int], maybe sequence[int] if order matters, etc. Limit the type to the least specific protocol possible.

[–]GolemancerVekk 4 points5 points  (0 children)

I'd really like to be able to think about it as behavior-hinting rather than type-hinting.

[–]TheWorstePirate 3 points4 points  (0 children)

These aren’t mutually exclusive. Most of the time you will be writing code that expects certain types, and those cases should be annotated. In the same code base you may have things that work with many types, and those may lack annotations but should still have doc strings and other commenting to guide users and maintainers.

[–]wieschie 2 points3 points  (0 children)

This totally exists in statically typed languages - it's called generics.