2 ms·
To replace `if(x instanceof a)`, you don't need type polymorphism (way too heavy). You need algebraic datatypes. With pattern matching (a glorified `switch`),
by loup-vaillant 17y ago
To replace `if(x instanceof a)`, you don't need type polymorphism (way too heavy). You need algebraic datatypes. With pattern matching (a glorified `switch`), you have the best of both worlds: the compiler make sure you cover all cases (and warn you if you don't), and the code is still local (you don't have to fetch several files to assess its behaviour). If you want to add one case, you still have to modify several snippets, but again, the compiler will warn you if you forget one.
Of course, if their language don't have algebraic datatypes, I strongly suggest they learn one that have it.