5 ms·
Structural typing is enforced at compile time, duck typing is "enforced" at runtime (by going up in a burst of smoke if you provide something that doesn't quack
by wk_end 5y ago
Structural typing is enforced at compile time, duck typing is "enforced" at runtime (by going up in a burst of smoke if you provide something that doesn't quack like a duck).
- ninkendo 5y agoDuck typing can still be a compile-time thing… C++ templates are “duck typed” in that the template can’t specify the bounds for the passed-in type, but if you pass the wrong type, it still breaks at compile time instead of runtime. (It’s just that the error messages are way more impenetrable than they otherwise could be.)
- wk_end 5y agoI’d argue that either “runtime is compile time in the case of C++ templates” and/or “C++ templates are structurally typed”, especially now that concepts are a thing. ETA: and/or that talking about C++ templates as "typed" one way or another is problematic, given that they're a part of the type system.