jargon

Comparison

Duck typingvsNominal vs structural typing

Duck typing

nothing declared a shared type anywhere, and the code worked because both objects happened to have the method.

Relying on an object having the right methods at runtime rather than on any declared type relationship. It is structural typing without the compiler: extremely convenient, and it moves the entire class of mismatch errors from build time to the moment that line of code is finally reached. Test coverage is what stands in for the type checker in a duck-typed codebase, which is why those communities tend to care about it more.

Full entry →

Nominal vs structural typing

the object had every method the interface asked for and the compiler still refused it, because it had not said it implemented it.

Nominal typing decides compatibility by the declared name — a type fits only if it says it does; structural typing decides by shape — a type fits if it has the right members. It explains why the same code is accepted by one language and rejected by another, and why interfaces feel heavier in some ecosystems than others. Structural typing makes test doubles and adapters nearly free; nominal typing makes the intent explicit and catches accidental compatibility.

Full entry →

Related comparisons