I'm using CounterClockWise to develop my first Clojure project on the Windows 7 OS. Besides javascript (which I'm not too familiar with), this is my first dynamically typed language.
The hardest part of building my project was debugging the issues I had. The technique I've been using is to sprinkle println
s in places to confirm my inputs and outputs are what I want them to be.
Compared to Java, it seems that a lot of Clojure functions accept what I'd consider garbage input and happily return nil. As a result, the runtime exception you see can come from many functions away from the cause of the problem. My point being, it can be hard to even know where to put the println
s.
And, these runtime exceptions were outputing compiled code line numbers so they weren't very informative. Most of my functions were short and side-effect free but the problem is my inputs were webpages. Sometimes the input to a function was the raw html, sometimes it was the parsed html (by enlive), sometimes it was a list of links (by using a css-like selector on the parsed html). These inputs could be deeply nested, complex structures (ie: a list of maps of maps of lists of maps) so it wasn't easy to build them up by hand. When you've got a stack trace that's not pointing to the issue, I'd pretty much have to debug half my program and figure out how to generate inputs to each part. It was pretty time consuming.
On the IRC channel someone informed me of the stacktrace library which made debugging that much easier. It still pointed many functions away from the source of the bad input, but it was still helpful. I'm looking for more techniques like this. What are some techniques I can use to debug my code better?