4 ms·
> What thing that violates a type check would be "perfectly fine to do"? A typical example, in dynamic programming languages, is to treat numbers as strings an
by AQXt 6y ago
> What thing that violates a type check would be "perfectly fine to do"?
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 https://en.wikipedia.org/wiki/Duck_typing).
- ArchieMaclean 6y agoCan you give an example of where doing this is useful?
- smabie 6y agothat sounds really awful, not "fine."
- adwn 6y ago> A typical example, in dynamic programming languages, is to treat numbers as strings and vice-versa That sounds great until it bites you in the ass really hard. In general, you want to catch unintended behavior as early as possible.
- astrange 6y agoYou want to, but they don’t. Those people just want to get stuff done, as opposed to a language like Haskell or stricter where you’ll never be able to get old code to run because newer compilers print errors that take a week to understand. There’s some old Yegge articles about this… PHP converting between strings and numbers is usually a mistake, but the one data structure doing everything (array and dict) is nice enough.
- bjoli 6y agoI don't think that is necessarily a dynamic language thing: that seems like your regular ad hoc polymorphism. Pascal allows it, IIIRC. So does C#. Being able to use a function on different kinds of arguments is orthogonal to the typing discussion. Scheme, for example, is dynamic yet very monomorphic. You have length (working only on lists), string-length, vector-length, bytevector-length etc.