14 ms·
The advantage is clarity in the calling function. With type safety checks, you're mostly eliminating a class of problem by ensuring coders don't call the funct
by pryce 7y ago
The advantage is clarity in the calling function.
With type safety checks, you're mostly eliminating a class of problem by ensuring coders don't call the function with some argumetn of a type they didn't mean to.
But suppose I have a method that takes 5 different strings and performs some computation on them - the type safety check doesn't help me there.
In functions that take multiple arguments of the same type, it can be easy to be mistaken about the intended order of parameters, for example passing the 5 strings (name, address, level, phonenumber, cellphonenumber instead of in the order the function expects (name, address, phonenumber, cellphonenumber, level).
Named parameters -if using meaningful names- make it clear in the calling function the semantics of which parameter has which meaning, so the above mistake gets caught at compile time instead of (worst case) not at all.
Of course, in functions with arguments of heterogenous types they're probably overkill.
- deleted 7y ago[deleted]