Re:Interfaces Generally Belong with Users
by hesk on Saturday November 23, 2019 @04:29PM
(#21616694)
Sounds a lot like Python's duck typing to me. (Although Python would coerce the types if they don't match.)
[ Parent
| on HN ]
Re:Interfaces Generally Belong with Users
by kevincox on Saturday November 23, 2019 @04:54PM
(#21616853)
It is. "Structural typing" is basically "compile time duck typing".
One major notable advantage is that you are checking the existence of every method you may call, not just the ones your tests happen to use.
Javascript (without typescript) also has duck typing. The difference with structural typing is that the interface is formalized and enforced compile time.
Python 3.7 added compile structural typing using what they call Protocols. It works very similar to typescript. See https://www.python.org/dev/peps/pep-0544/
Re:Interfaces Generally Belong with Users
by mcqueenjordan on Saturday November 23, 2019 @05:53PM
(#21617162)
Similar in some ways, but duck typing is a misnomer because it doesn't involve typing.
These are type classes, or what Rust calls Traits.