17

Quite a few of the questions on SO are more or less warranted requests for help with a debugging problem, often from people who give the impression of not really knowing techniques and tools to debug.

Could we have some general debugging tutorial/training/instruction material to point to?

If there were such resources, one could ask if the poster has tried the debugging techniques listed, and once they have, the community could step in with some croudsourced debugging.

The reason for this question is that often a few well-placed printf()'s (or similar, depending on the language/platform) would help a lot to narrow down the problem. And quite some effort (usually in the comments) could be spared.

Another general tool that it would be useful for some posters to know is a debugger (again, for languages, platforms and development environments that provide one).

Instead of people walking the poster a debugging session, people wanting to help could just post a link to this generic resource. It could take the form of a few practical FAQ entries, with a few basic debugging steps for a couple of categories, for instance environments with a debugger, environments without one (many web development platforms) and HTML/CSS and friends.

4
  • If its web based development I usually mention the powerful chrome dev tools...
    – Lix
    Feb 19, 2012 at 18:22
  • Not a bad idea, but if the poster does not know how to use them, they may not be able to bring back useful information to add to the original question (which is often just a wall of code)
    – Monolo
    Feb 19, 2012 at 18:34
  • Related: meta.stackexchange.com/questions/58668/…
    – Shog9
    Feb 19, 2012 at 18:35
  • I didn't really mean post a link and run... You have to give some details or insight on how to use tool. I thought the chrome dev tools was just a great example because it is so widely used and anyone who uses chrome already has it.
    – Lix
    Feb 19, 2012 at 19:08

3 Answers 3

8

Whatever you do, do not just throw the OP a fixed piece of code that "works". It may help them in the short run, but it fosters a culture of dependency and suggests that these kinds of questions are okay to ask here, which they are really not (and I'm saying this as somebody who has done a lot of one-on-one debugging help on SO.)

The ideal approach would be to point out the mistake, and explain to the OP what debugging tools you used to find the problem.

However, the vast amount of incoming questions on Stack Overflow these days makes it impossible to do so for every "what's wrong with this code" type question. Keep in mind that these kinds of questions are almost always textbook "too localized" and it's perfectly okay to vote to close them as such.

6

You don't teach someone how to swim when they're drowning.

If someone asks a debugging question in good faith, they're probably staring at a wall of code (or a page full of "tags") with no idea of what (or why) things don't work as they're supposed to do. As experienced programmers we know how to approach this problem, we know how to peel away layers of code to figure out what's working and what's not. We know how to use the tools, but to be honest, the tools are secondary: they make us more efficient, they don't do the debugging for us.

What to do

  • Answer the question. If you have the time, explain how you found the bug.
  • If a tool would make fixing this problem easier, point them to the tool, but remember the tool is secondary: the developer is the best Debugger. If the tool makes things 1000 times faster for you, it's because you already know the ins and outs of the problem. The tool without your knowledge does nothing.
2
  • Sorry if I gave the impression that I would focus on the tools, it was definitely the debugging techniques that I wanted to promote. And the problem with your very nice proposal is that you get to repeat yourself many, many times. And as we know here, don't repeat yourself (DRY), that is what computers are good at.
    – Monolo
    Feb 20, 2012 at 10:06
  • 3
    Strongly disagree with the "drowning" analogy. Nobody's life is threatened here; it's just somebody who is unable or unwilling to do basic debugging, a skill every programmer must possess. I help with debugging often enough out of sympathy with the OP, but it is not our obligation to provide this kind of help. Being nice is great, but it's also perfectly okay to point the OP to a resource that teaches basic debugging, vote to close, and walk away.
    – Pekka
    Aug 22, 2012 at 19:24
0

Since no language tags are relevant in MSO, I will attempt answer this question from my view as a web developer.

When a question gets posted and the solution is some simple debugging I would post a comment referring to the chrome developers tools. As brought to my attention this post is also related here; Simply saying "use this debugging tool" is not enough and in the case of web development much can be said and learnt from the chrome dev tools.

The actual content depends obviously on what debugging advice you are giving.

In PHP some advice could be to write all error messages to a log file or the method detailed by the OP : placing some crutial echo statements throughout the code and seeing what the output is... But saying "use x-debug" would not really help the poor guy out.

In the end the question usually is not titled "Effective debugging techniques" so any post simply teaching the OP how to debug effectively essentially does not answer the question.
I think debugging advice should be given but contained in comments among other phrases like :

...and then update your question with more details

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .