Re:Don't use functions as callbacks unless they're designed ...
by btinker on Saturday February 06, 2021 @05:58AM
(#26045742)
It would check the arguments and return type of the function. Map takes a function with three arguments, toReadableNumber only takes one, therefore the functions are of a different type. So someNumbers.map(toReadableNumber) would be an error and not execute at all, instead of being a "bad practice" / potential mistake.
[ Parent
| on HN ]
Re:Don't use functions as callbacks unless they're designed ...
by dsego on Saturday February 06, 2021 @08:30AM
(#26046358)
What if toReadable also takes 3 args of the same type but different meaning?
Re:Don't use functions as callbacks unless they're designed ...
by flohofwoe on Saturday February 06, 2021 @09:18AM
(#26046626)
You can create custom types to communicate semantics to the type checker. Whether that's always a good idea is arguable though, but the tools are there (e.g. there's a wide field between weak and strong typing, and an overly strong type checker can be quite a hassle to work with while an overly weak type checker isn't much better than duck typing).