54

There are a myriad of questions saying "My code doesn't work" without any mention as to the the error they are getting in their debuggers/consoles etc..

I suspect that in most cases, the OP doesn't even know how to use a debugger/console (which is hidden to a person just starting out in JS for example, where a compiler is not present to alert him).

So what they see is usually their code not working for no (apparent) reason and without any knowledge that if they press F12(case for JS) they can see where the bug is.

The answers on this type of questions are usually code fixes - They don't address the core issue that is that the OP doesn't even know what/how to use a debugger.

If we provide just code fixes they'll stay oblivious to it's usefulness/purpose and ask another question later on that is just as basic/localised as the one they just asked.

Should answers like that just be provided code fixes or is there a different mechanism we can use?

Ideally, it would be better if we could prevent the question from being asked in the first place (hopefully the OP solves the issue on his own). This frees up resources to answer questions that have a more perplexing problem to solve.

11
  • 8
    Comment on the question, asking the OP to note error messages in the console (which you may need to follow up with the F12 keystroke). Then the OP has learned that the console exists and errors are listed somewhere and can improve the question, and start searching the web for the error message. Everyone wins. Meanwhile, someone else will post the code solution you hesitate to post. Commented Dec 21, 2015 at 12:58
  • 12
    Keep in mind that Stack Overflow does not exist to teach someone how to be a programmer, so making it a mission to try to teach someone to use a debugger is not going to work. So the appropriate answer to such questions is to address the issue in the question (why doesn't my code work). Telling them to use the debugger and maybe some hints as to how to do it is best left for comments (or as a supplement to an actual answer) Commented Dec 21, 2015 at 13:01
  • @MichaelBerkowski Isn't the solution something that will eventually prevent the question from being asked in the first place? Something along the lines of a warning to the user to have the error message of his debugger in the question itself. Commented Dec 21, 2015 at 13:01
  • @psubsee2003 I don't think we should teach them how to use the debugger either, but perhaps we could try and prevent them from asking the question unless they have an actual error message at hand before asking. Commented Dec 21, 2015 at 13:02
  • 5
    @NicholasKyriakides sorry, I didn't pick that up from your question. Since that is your primary point, there is already a solution - there is a close reason already for questions like the one you describe. Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, **a specific problem or error** and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. Commented Dec 21, 2015 at 13:06
  • 5
    I have a canned comment, when asking people to check the JS Console, that links to How to open the JavaScript console in different browsers? on Webmasters.SE. Minimal effort and hopefully informative.
    – Paul Roub
    Commented Dec 21, 2015 at 13:16
  • 1
    @NicholasKyriakides That is implicit in my comment. But where you'll find many users in the community who take the approach of "warning" the OP, I take the approach of politely informing them of something they may not already know about. Your original point was that the OP may not even know an error console or debugger exists, and so I suggest you politely tell them where to find it, and request the question be edited to include it. If that doesn't happen, move on to the "Why isn't this code working" closevote. Commented Dec 21, 2015 at 13:16
  • @MichaelBerkowski But wouldn't it be better if we could prevent the question from being asked in the first place (hopefully the OP solves the issue on his own). This frees up resources to answer questions that have a more perplexing problem to solve. Commented Dec 21, 2015 at 13:22
  • 2
    @NicholasKyriakides That's been raised many of times here, trying to get features like a checklist/walkthrough for asking during the process, etc. Direct the OP to How to Ask, which can even be done with the handy comment shortcut [ask]. Commented Dec 21, 2015 at 13:25
  • 3
    @psubsee2003, that's not solution. That's doing someone's work with fixing highly localized problem that won't ever help anyone else and most likely won't help this particular person outside this particular case too. There's zero reason to preserve such Q&A online. Commented Dec 21, 2015 at 13:29
  • @OlegV.Volkov but closing the question is the first step to deletion. Yes, it would be ideal if we could prevent the questions beforehand, but since we can't the next best thing to do is close them first, downvote them as appropriate, and have the users with the requisite rep start casting delete votes once the OP's has been given a fair chance to improve the question. Commented Dec 22, 2015 at 15:52

5 Answers 5

46

On question where the OP can easily fix the problem using a debugger I tend to leave an auto comment with:

It sounds like you may need to learn how to use a debugger to step through your code. With a good debugger, you can execute your program line by line and see where it is deviating from what you expect. This is an essential tool if you are going to do any programming. Further reading: How to debug small programs

I try not to answer them as learning how to debug code is a very useful skill and can quite helpful. I believe in the old adage

Give a man a fish he eats for a day. Teach a man to fish he eats for life.

The problem with trying to teach the OP how to debug is that SO isn't really the right place to do this. You could include in your answer how you found what was wrong and how to fix it but some people might not like that as it contains a lot of extra information that is not really "useful" except for the OP. Remember answers are not just for the OP but for anyone else with this problem and if you bury the answer a bunch of debugging information it makes getting the answer harder and you may even get down votes for it.

11
  • Actually that's the same proverb that came to my mind and I asked this question. Commented Dec 21, 2015 at 13:11
  • @NicholasKyriakides In my opinion it is true. Also I added some more to my answer. Commented Dec 21, 2015 at 13:16
  • 7
    Rep whores might cite: «Give a man a fish he eats for a day. Teach him how to fish you destroy a business model.» Commented Dec 21, 2015 at 19:01
  • 4
    @vikingosegundo lol. They might but I really don't care. I would rather have more competent programmers out there then more people who just live off of SO solving their problems. Commented Dec 21, 2015 at 19:03
  • 1
    Me too. Often I comment on questions that the issues are too basic and proves that OP needs to get some programming understanding prior asking as we cannot provide online tutoring. But in the past few months I noticed that such comments are deleted by moderators shortly after. So I am not sure that my point of view still reflects the common understanding here. Commented Dec 21, 2015 at 19:09
  • @vikingosegundo It is okay comments get deleted as they are transient and technically they do not add to the question. All I hope for is the OP sees it and learns from it. There isn't much more we can do on SO about that. Commented Dec 21, 2015 at 19:11
  • 1
    I don't agree. It has to be a comment, as it isn't answering the question, but it is valuable for the op and future reader to get the scope of SO right. Commented Dec 21, 2015 at 19:13
  • 2
    I prefer this quote: Give a man a fire and he's warm for the day. But set fire to him and he's warm for the rest of his life.
    – DavidG
    Commented Dec 22, 2015 at 9:28
  • @DavidG That.. sounded a bit morbid at a first glance - but then again I'm not a native English speaker so it took me some time to get the point behind it, hehe Commented Dec 22, 2015 at 19:33
  • 1
    Never actually state the old adage along with the response about debugging. :) I made that mistake (with sincere intent) and I was shot down from every side as being arrogant, insulting and demeaning. That was apparently obvious to everyone else reading the post and my comment was removed by a moderator. But to me it was obvious that the poster was lacking some fundamental knowledge about how to approach the code. It's ironic that meta is full of questions about low quality debugging and newbie questions, but any attempt to actively address such issues in comments are met with hostility.
    – C Perkins
    Commented Jun 30, 2017 at 15:42
  • Here's the raw markdown, for easier copying: It sounds like you may need to learn how to use a debugger to step through your code. With a good debugger, you can execute your program line by line and see where it is deviating from what you expect. This is an essential tool if you are going to do any programming. Further reading: [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)
    – Ezra
    Commented Jun 29, 2021 at 23:15
10

In case it not logic error, but syntax error that would be pretty obvious from just error message, I'd just cast a close vote with off-topic > This question was caused by a problem that can no longer be reproduced or a simple typographical error reason. It's complete description is pretty close to situation you talk about.

If user don't have even basic debugging knowledge - i.e. ability to extract and post error message - that means that his post won't contain any pattern that would help any future visitors with same problem to find it. Therefore such questions must be either improved by original poster (you can use comments to give him short pointer to debugging facilities) or closed, because those Q&A serve no use for anyone else as long as nobody can ever find them.

6
  • 1
    But that doesn't directly help the OP - it only helps the site. I'm thinking that they don't even know what a debugger is - it's just benign ignorance on their part. Commented Dec 21, 2015 at 13:34
  • 5
    @NicholasKyriakides, SO doesn't promise to help each and every person personally with each possible question. That would be simply impossible. That's why there are on/off-topic rules and limitations, so Q&A would be useful to other people. This particular question is off-topic. You can still leave a comment with short pointers to debugging facilities. Commented Dec 21, 2015 at 13:40
  • I'd agree if it was a rare scenario - these questions just keep popping up so I doubt that "each and every person" is applicable here Commented Dec 21, 2015 at 13:41
  • 3
    @NicholasKyriakides, no, it wouldn't. Try to place yourself in the shoes of next user who doesn't know how to debug and imagine what search terms would you use to when you have similar problem to hit that "previous question with how to debug answer". You'll see that there's none - if previous user didn't even knew how to read error message, that means previous Q don't have it in readily searchable form. Commented Dec 21, 2015 at 13:44
  • @NicholasKyriakides, I've extended answer with those points. Commented Dec 21, 2015 at 13:47
  • What about the close-vote for specifically debugging?: Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it. Commented Dec 22, 2015 at 0:33
3

Maybe a solution can be similar to what Anime and Manga.SE does with Identification Request questions which are easily answerable by a Reverse Image Search. this is done by have an answered Question indicating how one does a Reverse Image Serach (along with other methods as answers such as doing it for animated .gifs or iding characters within an image) which can then be used as a duplicate question link.

for Stack Overflow you could probably do what NathanOliver has put up for an auto comment but instead fleshing it out a bit and quoting the relevant sections of the external link.

If the question gets closed as duplicate of a "Basics of Debugging" Question but the OP says that didn't help then the OP can then edit their question with more info in an attempt to get it re-opened as they should

3

I think this is where we can make use of .

This is a related question question : Providing "Art of debugging code" documentation via StackDoc

Once we have good documentation on debugging a specific language, what I suggest is giving gold badge users of that language the ability to hammer the question if they think the issue can be solved by doing basic debugging or OP needs to provide more information by debugging the problem.

Leaving the question on hold with a message like:

It is likely that this problem can be solved easily by doing basic debugging. (link to documentation to debugging). If the issue persists, Please edit the question and add the information you found after debugging following the documentation and explain why it didn't solve the problem.

Also create magic links to these documentation so that users who doesn't have hammer privilege can easily leave a comment pointing OP to the documentation, or give the OP his fish along with the link to learn fishing, whichever they prefer.

-6

A good idea I think is to add a header to SO, or a message when you first create your account. "The Basics of Debugging" or "Why debugging is important and why you should try it before you ask questions on Stack Overflow." Or something like "PLEASE DO NOT POST QUESTIONS WITHOUT READING THIS!" and it teaches you basics of code, debugging, best practices, yadayada.

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