4 ms·
> Duck typing vastly reduces the amount of code one has to write that does nothing, making the purpose of the code much more clear. The tradeoff is in compilati
by lmm 11y ago
> Duck typing vastly reduces the amount of code one has to write that does nothing, making the purpose of the code much more clear. The tradeoff is in compilation, not clarity of purpose. The code tends to be more flexible to changes in the underlying data, as it is easier to modify!
It's much harder to make changes because even something like renaming a field requires major testing. You end up writing much more code that does nothing, because the test coverage you need for everything is much longer than the type annotations that would give you the same level of confidence, and whenever you change anything you have to update all your tests by hand. Hope you get the data model right first time! Look at one of those videos of people refactoring Haskell for what a type system can get you.
> A sad example of those defending static typing are the Java programmers. I point out that Java supports duck typing via reflection, even if the syntax is painful. They say they don't use reflection, they use Spring. [Head in hands]
If Java is what you think of when you think of static typing, I don't blame you for hating it. If Java-style typing and duck typing were the only options I'd use duck typing. But there are much better options out there. When I write Scala, most of the time my code looks exactly the same as what I'd write in Python.