by AQXt · 5y ago · 0 comments
A typical example, in dynamic programming languages, is to treat numbers as strings and vice-versa; evaluate lists in boolean context; and so on.
> If value is not a numeric type, square is not going to be happy. And that's the case with most (all?) dynamic code.
Some programming languages will be glad to accept a string and treat it as a number -- see Duck Typing (https://en.wikipedia.org/wiki/Duck_typing).
That sounds great until it bites you in the ass really hard. In general, you want to catch unintended behavior as early as possible.
PHP converting between strings and numbers is usually a mistake, but the one data structure doing everything (array and dict) is nice enough.
Scheme, for example, is dynamic yet very monomorphic. You have length (working only on lists), string-length, vector-length, bytevector-length etc.