Suppose I have an application written in clojure which generates code while it is running. How can I debug that code – for which I do not have the source code?
Edit: I’m asking this question, because I was chatting about clojure with my colleague and he said that clojure programs are hard (or impossible) to test because of the reason stated above. I thought that this is a rater pessimistic approach. If it were untestable no one would’ve used it.
Clojure gives you so much power so you don’t need
debugdeveloping style which is common in other less powerful languages like java, c++, etc.If you keep this programming style you will reduce the chance when you really need debugging.
You can do all the job by REPL in your case. You can get input parameters of functions that generate the “debugging” dynamic code by logging . After that you would get input parameters of this dynamic code in the same way. You would have both the generated “debugging” code and input parameters at the end. So you can easily reproduce situation and test it.
Update. Regarding edited part of the question it’s not correct to say that “clojure programs are hard (or impossible) to test” just because your program generates code on the fly. Keep in mind that generated code is still the data which can be manipulated as usual data collections. You don’t need to build, run and freeze the whole application at the breakpoint to see what’s going on there. I’ve already described the way you can test your dynamic code.