When I learned Java, I tried to use jdb for some debugging but couldn't get my head around debugging from the "command line". I never managed to learn that. 8+ years later, even today, I cannot connect the context from a jdb- or gdb-style debugger with code in an editor.
But I learned another way of debugging: System.err.println
. Just add a few print statements in the places you think are interesting and rerun your code. (Some people are surprised when I say I find using print statements faster than using an interactive debugger.) One thing I like about print statements is that it's so universal: I never have to learn how to use a new debugger. It works the same way in all kinds of enviroments including Python, C++, and JavaScript.
The latest toy I've built, FotoBloger, has a mysterious bug that kicks in only when a friend of mine uses the app. I have been trying to reproduce the bug from my account for a few weeks, but with no success. Yesterday, I decided I had no way but to do some "remote debugging" when my friend is using the app. My universal "print what's interesting" approach works really well in this bizarre remote debugging scenario as well :)
I added a /debug
URI to the app which won't do anything apart from sending a 204 (no content) response back. Next time the app is being used, it will make a bunch of /debug requests with the data I want to inspect in its query string. The server logs all incoming requests, so I can look at the logs to see what those values were and maybe I can discover the bug. (Can your interactive debugger do this? ;-)
No comments:
Post a Comment