4 ms·
Interface typing > duck typing. With any sort of code completion, it's 1000x easier and more productive to figure out what goes where when the computer has some
by kortex 6y ago
Interface typing > duck typing. With any sort of code completion, it's 1000x easier and more productive to figure out what goes where when the computer has some idea of the types of a given varaible, and hence what operations you can do to it.
It's like duck typing with a built-in Audubon society taxonomy chart.
You can always do whatever you want at runtime, it's still python.
IMHO, duck typing is strictly inferior to interface typing. You'd define a `Number` interface which `int`, `float`, ect all implement.
- pansa2 6y ago> Interface typing > duck typing. Duck typing has been fundamental to Python for a long time. Do you think we're seeing a shift away from it? In the future, do you think "Pythonic" code will include significant use of explicit interfaces?
- dragonwriter 6y ago> Duck typing has been fundamental to Python for a long time. Do you think we're seeing a shift away from it? We have been since at least the introduction of abstract base classes; even in purely dynamic python, having the ability to more explicitly declare and interrogate intent than pure duck typing is frequently useful. > do you think "Pythonic" code will include significant use of explicit interfaces? Sure, as it already does via abcs. But it will also still use lots of duck typing, though over time more of it will be “static duck typing” by way of protocols. https://mypy.readthedocs.io/en/stable/protocols.html https://mypy.readthedocs.io/en/stable/protocols.html
- deleted 6y ago[deleted]
- raverbashing 6y agoYes but if you want Interface Typing use Java. But of course give the slightest whiff of types and the type police will come and want to shove types down your throat all the way