3 ms·
I largely agree with this, but also consider the following: 1. I have a function 'saveScore' that has a parameter 'score' that is an int. 2. Users of my funct
by humanrebar 13y ago
I largely agree with this, but also consider the following:
1. I have a function 'saveScore' that has a parameter 'score' that is an int.
2. Users of my function frequently misuse my function, passing in negative scores, so my team decides a range-checked Score parameter makes more sense.
3a. In a static language, users of my new code get compilation errors saying 'saveScore' takes a 'Score', not an int.
3b. In a dynamic language, at best, devs that use my code get an easy-to-read exception thrown at runtime. This assumes I'm thorough enough to check my preconditions and throw an understandable error message. This also assumes all code paths are covered before the code is released to customers.
In short, static languages provide facilities for library and framework authors to enforce a little discipline in the consumers of their code.
- spion 13y agoNow what if you have a function that returns an int, which you want to use as the input argument to saveScore? You'd probably use a conversion function that returns a Maybe Score...