4 ms·
Well, using the type system, weak or strong, to force correct code either at compile time or runtime would help. I can write a function that uses Java reflectio
by andrewstuart2 10y ago
Well, using the type system, weak or strong, to force correct code either at compile time or runtime would help. I can write a function that uses Java reflection for polymorphism as easily as I can use JavaScript reflection to enforce an API contract.
// JavaScript
if ( Array.isArray(address) ) {
throw new Error("Must only pass a single email address.");
}
// Java
void sendEmail(Object recipientOrRecipients) { ... }
There are times when polymorphism is low-risk, and there are times when it's better safe than sorry. Best to know your risk model (and your libraries) and act accordingly.