Currently, when I refactor in Clojure, I use a template:
(defn my-func [arg1 arg2] (assert (= demo.core.Record1 (class arg1) "Incorrect class for arg1: " (class arg1)) (assert (= demo.core.Record1 (class arg2) "Incorrect class for arg2: " (class arg2)) ...
That is, I find that I manually check return types in case the downstream part of the system changes them to something that I do not expect. (As in the case when I refactor and get a stack trace, I do not expect, then I express my assumptions as invariants and backtrack from there).
In a way, this is exactly the kind of invariant test that Bertrand Mayer expected. (The author of "Object-oriented software" , and a supporter of the idea of Design by contract ).
The problem is that I do not find them until runtime. I would be happy to find them at compile time simply by specifying what the function expects.
Now I know that Clojure is essentially a dynamic language. (While Clojure has a "compiler" of sorts, we should expect that applying values to a function will only be implemented at runtime.)
I just want a good template to simplify refactoring. (i.e., to see all the effects of the transition from changing the argument to the function, not seeing it break into the first call, then move to the next, and then move to the next break.)
My question is: Is there a way to check return types when refactoring?
source share