3 ms·
> Even in a dynamically typed language, you have to know what sort of arguments a function expects; otherwise, how can you write any code at all to operate on t
by UncleEntity 9y ago
> Even in a dynamically typed language, you have to know what sort of arguments a function expects; otherwise, how can you write any code at all to operate on those values if you don't even know what they are?
Not necessarily...
If the value passed to function implements whatever functionality called then its type doesn't really matter. Really the whole theory behind duck typing.
>>> i = 1 + "1"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
while javascript (apparently) will assign "11" to i.
- RussianCow 9y agoIf you operate on a value, you are assuming that the value supports that operation, which means you have some information on the interface that the value supports (i.e. a type). If you had absolutely no information about the interface of a value, you could not possibly do anything with it. There is actually an entire category of static type systems called "structural type systems"[0], which is basically duck typing checked at compile-time rather than runtime. [0]: https://en.wikipedia.org/wiki/Structural_type_system https://en.wikipedia.org/wiki/Structural_type_system