4 ms·
> "Small example, in JS, if you have a function that works on a "age" property of an object, it doesn't matter what kind of object you send in, as long as it ha
by CmonDev 13y ago
> "Small example, in JS, if you have a function that works on a "age" property of an object, it doesn't matter what kind of object you send in, as long as it has an "age" property."
Shouldn't you just pass the 'age' property then?
- Skinney 13y agoDepends what operation you are performing. increaseAge function would probably require the object to actually increase the age, not just return an increased age value. This is a poor example, i know, but the point is that while both is simple operations in both static and dynamically typed languages, dynamically typed languages allow you to do this without writing an interface, generic function, abstract base class or whatever and restricting the function to that particular use case. The tradeoff is flexibility vs safety. I personally prefer dynamically typed languages as I've found that with a combination of discipline and unit-tests (which, IMHO, you should have anyway) I never really miss the static type-checker. But I understand those people who prefer static typing very well.