3 ms·
Having a proper type system can be immensely powerful. IMHO, duck typing is just adding the burden of type checking to the application layer instead of letting
by cerved 4y ago
Having a proper type system can be immensely powerful. IMHO, duck typing is just adding the burden of type checking to the application layer instead of letting a compiler or linter deal with it. Pythons lack of a good type system is what I miss most
- oivey 4y agoDuck typing is a superset of inheritance. If your language only supports polymorphism via inheritance, then it is strictly less expressive than a language with duck typing.
- tremon 4y agoWhat does superset mean, here? Inheritance can mandate the presence of certain fields at compile time, which duck typing cannot do, so it doesn't fit my traditional definition of "superset".
- deleted 4y ago[deleted]
- wnoise 4y agoSome forms of duck typing absolutely can do this. "Row polymorphism" is the general feature that allows this, some duck typing can handle this, some can't.
- Doxin 4y agoThe compiler can still do type checking even when using duck typing. It's important to note that duck typing and weak typing are entirely orthogonal. You can have either, both, or neither. E.g. an example in D of a function that doesn't care too much about the type you pass in: T doublify(T)(T v){ return v*2; } These are all fine: writeln(doublify(3)); writeln(doublify(3.0)); writeln(doublify(3u)); But this still throws a compile error like you'd expect: writeln(doublify("3"));