Is there a way to avoid the debugger?
I don't like debugging in the debugger because I think it is often below the abstraction level of the programming language, and it often fails to reproduce. I prefer to use unit tests whenever possible and I think they are good, but they are not always easy to implement. Do you know of any other alternative approaches to avoid using the debugger?
a source to share
A debugger is a tool saying that I want to avoid the debugger, like a carpenter saying that I want to avoid the hammer. You'd better ask the question When should I avoid using the debugger?
The times when you should avoid using the debugger are
- When you have no idea what the code is doing, first understand, try debugging, otherwise you are wasting time
- The problem is due to timing constraints (race conditions, IPC or streaming issues), if it's a sync condition and you start a single step then you won't be able to reproduce your problem.
I'm sure there are other times when using a debugger is a bad idea, but my question is that your question is wrong. Don't ask how I shouldn't use the debugger, but ask when I / shouldn't use the debugger.
my 2cents
a source to share
Contract design, unit tests and the like help ensure that a block of code, most often a function, works as it should. It's okay for this, but it doesn't replace debugging.
Debugging means figuring out why a block of code isn't behaving the way it should. A unit test can only tell you that a unit is not working as expected, it cannot tell you why. To find out why, you need to go through the code line by line, keeping track of where the state differs from what you expect, or where the branch is unexpected. To track these things, you need to check the status at any given time. You can do this with operators print
, using them to get state variables or to output logical branching. The debugger is a tool that can help you avoid changing your code.
You will need to use one of these. Even a unit test is basically a statement print
that automatically checks for correctness, only at a different level of detail.
You seem to want to do the actual code fix without looking at it. You can put tests and contracts around your code, whatever you want, if these things tell you about a bug in your code, you end up having to look at it. If you want to test the code without changing it by adding in instructions print
, the only tool is the debugger. If no major breakthrough occurs, then the state of affairs.
a source to share
Any non-trivial application should have some sort of logging / tracing mechanism built into it. You will want to enable / disable various kinds of output.
It is especially helpful to record all input data. It is much easier to reproduce the problems if you can "reproduce" the input.
a source to share
Personally, I rarely use the debugger myself. I usually find myself spending way too much time on a single tap and usually fiddling with the mechanics before I get to the part that matters.
My favorite debugging technique is to simply add print reports at strategic locations. For example, if a calculation comes up with a wrong answer, I can add print instructions to reset the values โโthat go into the calculation.
In Java, I usually write something like
System.out.println ("In function foo: bar =" + bar + ", plugh =" + plugh);
If the problem is which path the program has followed through the logic, I'll add instructions that print "to enter a sales block" or "finish writing to the database" or whatever.
I only resort to a debugger when I have no idea what the problem is and I can't think of anything better than going through each step to see where it went wrong.
a source to share
one strategy is to design a "debug" mode in which the application provides some useful information such as resources used, http variables, logs, SQL commands, etc ...
For example, I have a web application that manages the state of a web page through hidden inputs and that interacts with a database with xml messages ...
when I add the "debug = 1" url to the url, all hidden inputs are shown in the collapsible field, as well as the xml-in and xml-out done ...
more, in debug mode I can double-click on a specific spot on the page to see the database configuration information, as well as a shortcut to "impersonate" users to check permissions ...
one of the latest additions is a resettable checkbox which shows me the time it tok builds the entire page and the time it takes to access the database
on the database side, we process this xml and generate multiple sql statements. If I add the xml tag <show-sql> 1 </ show_sql> instead of executing the query, I get an sql statement ... so I can "debug" the stored procedure from the sql console ...
you can develop all these things in a couple of days and I can assure you that it really pays off ...
to understand and understand what I am talking about you can take a look at the developer frontend with the symfony framework
http://www.symfony-project.org/book/1_0/16-Application-Management-Tools
it allows you to check several things like logged data, request and response content, actions performed, etc.
in short, prepare your application to be tested easily ...
a source to share