3 ms·
> ... static typing does not catch value-related bugs, but Clojure.spec can. Can you provide an example? > In a static type system, how easily would it be to
by yawaramin 9y ago
> ... static typing does not catch value-related bugs, but Clojure.spec can.
Can you provide an example?
> In a static type system, how easily would it be to exactly specify and guarantee that a function's second parameter is of a higher value than its first, or that a function's output is an integer between 5 and 50, etc?
Scala:
def foo(param1: Int, param2: Int): Int = {
require(param2 > param1, "Param2 must > param1")
param2 - param1 ensuring { result =>
result >= 5 && result <= 50
}
}