2 ms·
If I write a sqrt function in a dynamically typed language, I will write a test which verifies that it does something reasonable when given something other than
by plorkyeran 2y ago
If I write a sqrt function in a dynamically typed language, I will write a test which verifies that it does something reasonable when given something other than a number as input. I will not write that test in a statically typed language because it would not even be possible to write.
- t-writescode 2y agoYou also need to make sure to have at least 1 or 2 tests per instance where this function would be called remotely where you don't mock this function in remote calls, to make sure that the data types of the function aren't ignored, because the mock, since it doesn't have types either, might tolerate inputs to the function you didn't intend or have behavior you didn't intend if you refactor a type change.
- bazoom42 2y agoWhat is “something reasonable”? In Pyhon you get a runtime error automatically if you perform an operation not supported by the object, e.g performing a mathematical operation on an object which is not number-like. This is out of the box behavior in a duck-typed language, just like a compile-time error is out of the box in a statically typed language. Of course you need to test for NaN, Infinity etc because these are number-like but still invalid. But you also need to do that in a statically typed language.