I always use System.out.println(...) to debug my code, and it works pretty well. In which cases do you use the eclipse java debugger? I never had to use it and the little bug symbol is still ab bit mysterious to me. Are there cases where the debugger helps me that I can“t solve with a println?
|
|
||||
|
Every case... Granted, I'm not 100% sure about Java IDEs (and would welcome any corrections that aren't consistent with Java IDEs) because I use Visual Studio over C#/F# but adding variables to the watch list and using conditional breaks completely practically replaces println...
And hell, I'm not even that great with the debugger, but it's still light years ahead of console debugging or digging through logs. |
|||||||||||||||||||
|
|
The problem with println debugging is that the printlns themselves are a problem. When you're debugging using If your println diagnostics turn out not to give you useful information, or not to give you useful enough information, you need to close the program, change the code, recompile, and then get back to the point you were at to reproduce the bug. Once you're done with finding and fixing the bug, you then have to change your code again to remove the println statements. (Let's hope you don't miss any and then ship the product with debug output left in!) An interactive debugger doesn't have these problems. You don't need to know what you're looking for ahead of time; you can examine the values of any arbitrary variable at any time it's in scope. You don't need to modify your code, because the debugger is external to your program. And therefore you don't need to stop debugging, change your code and recompile to look at something new. That principle alone--inspecting the code from the outside instead of having to instrument it (and then un-instrument it) manually--is the reason interactive debuggers have become the favorite method of debugging among modern programmers. |
||||
|
|
|
There isn't really any information a debugger can give you that you could not gain through print statement as well, but... it's just so much faster and more flexible. Words can't describe the power you get when you can freely look at what the code is doing while it's running. All in all, I'd estimate that using a debugger typically speeds up the debugging process 10 times. Probably 100 times in cases where there's a lengthy build or deployment between the time where one print statement gives you information about where to next, i.e. where to add another print statement, and the time you can see the output of that new print statement. In a debugger, all it takes is a single click, maybe half a second. If you have to do a full rebuild and deploy to an app server, it could take half an hour. |
||||
|
|
|
in my experience, the eclipse debugger (or any step-by-step debugger, for that matter) helps a lot more than println statements, because:
(these are just the most basic advantages I found) However, the debugger is not always that nice:
in short: for small, handable projects a debugger is your largest friend. For large projects (which you often work on with a lot of people), an extensive write-time logging is your even larger friend. Or at least mine. |
|||
|
|
|
You should have googled it first. Debugger in Eclipse already contains a lot of functions that you don't need to define. Other than that, System.out.println() statements might do for you in a simple small project but in a project where many members are working or you have large number of files, you just can't keep adding these statements. It is good to have breakpoints. |
||||
|
|
|
I hardly ever find that I need the debugger - but when I need it, I really need it. One nasty case is where you use In the debugger, you will find immediately that the object is not The debugger lets you explore a wider range of questions, more quickly, than using |
|||
|
|
println?printlnharder!" But seriously, my point is that just because you can solve something withprintlndoesn't mean that it's the easiest, best or fastest way. So what kind of answer are you looking for? Also, don't forget that using print statements means you're constantly modifying code, which 1) takes effort and 2) introduces a possibility of accidental screw-ups. Why not use a logger? And is there a chance that your unit tests aren't as good as they could/should be? – Matt Fenwick Oct 11 '12 at 20:19