15

I am wondering, is there a certain format or template for debugging questions. I ask because recently my question was closed due to people complaining about:

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. See: How to create a Minimal, Complete, and Verifiable example https://stackoverflow.com/help/mcve."

I had a reproducible code snippet, I'm not sure what people were looking for, the output? I was thinking they could run it themselves. I got an answer, but not before the post was closed.

Here is the post

Getting the Mean by a Factor

6
  • 11
    I don't think StackOverflow is designed for "debugging requests"? Commented Apr 24, 2015 at 0:37
  • 4
    Comment #1 on the post is "What's your desired output of the function?" Commented Apr 24, 2015 at 16:59
  • 2
    What @MooingDuck said. We can run your code to tell what the output is. What you need to describe is what it should be. Commented Apr 24, 2015 at 17:42
  • 1
    it has flaws is a rather unclear problem statement Commented Apr 24, 2015 at 22:34
  • 1
    The first comment to your question gives you a good hint. If your function doesn't return the expected output, you should show the expected output and explain it. You should also include (a representative excerpt of) any output your function gives you, including error and warning messages. The goal here is to make it as easy as possible for others to understand your problem. Expecting them to run your code before they have decided to engage in your question already creates an obstacle.
    – Roland
    Commented Apr 25, 2015 at 9:42
  • 1
    And of course, SO is not a debugging service. Your goal should be to understand what you did wrong and find and understand a better way. Not to have others fix your code.
    – Roland
    Commented Apr 25, 2015 at 9:43

5 Answers 5

46

The issue with your question is that it doesn't contain what we need to help you. When we say we need an MCVE, that's exactly what we mean:

  • A minimal example that reproduces your issue. You're mostly there; but you could have reduced some of the input numbers to make it clearer.
  • A complete example: Does this provide everything we need to find an answer? Is there a function you're not showing us that you need to for us to help you?
  • A verifiable example: If I were to run your code, would I get the same results? The only way to figure that out is for you to run the minimal complete example on another machine or separate from your application code, to ensure it's not an environmental issue.

The other part of that close text says:

  • "a specific problem or error".

"It has flaws" is not a specific problem or error. I have flaws, but I'm not a specific problem or error either. I'm also not sure what you're trying to say here:

"The issue is that for xbar[l]***, l no longer corresponds to the index. "

  • "Questions without a clear problem statement" - "Help me fix" is not a problem statement. "I'm trying to average multiple rows in a table that contain various factors in R" is (this is only an example, based on my limited understanding).

So, if you want us to debug your code:

Include your inputs, your expected outputs, your actual outputs, a clear problem statement (what would you Google for to search for the answer to this problem? That should be in your title and your problem statement); and take care to format code as code.

1
  • 12
    It's also worth to consider that most SO users don't have access to a compiler when answering questions - or they don't want to start an IDE. However, they can still spot the problem immediately after seeing the difference between expected output and actual output.
    – Sulthan
    Commented Apr 24, 2015 at 17:20
19

Let's start with the phrasing:

I wrote this function but it has flaws

What flaws?? You don't tell us what's going on with the code or what the issue is.

Please help me write a fix. The issue is that for xbar[l]***, l no longer corresponds to the index.

It's tricky to help you write a fix understand what's going wrong if we don't have a good grasp of what's going wrong with the code.

Start with this:

  • What error you're running into
  • What you expect the result of the function to be
  • What the function is actually doing
  • What attempts you've made at fixing it and why they came up short is also decent to include

Most of all, phrasing is key here. If you come across as someone that's just looking for someone to help you fix the problem, that won't bode well for you either. Consider phrasing it in a way so that someone is encouraged to help you understand what's going wrong with it so you can avoid mistakes in the future.

1
  • 5
    Providing the expected output is very helpful.
    – ryanyuyu
    Commented Apr 23, 2015 at 14:40
5

Others have said that SO is not a debugging service. It might not be obvious why debugging requests aren't very welcome on SO; I'll try to elucidate.

A good question on SO is one that inspires good answers - answers that not only help the OP solve their current problem but will also be valuable to future readers. (See Optimizing For Pearls, Not Sand). Generally, debugging requests are highly specific, and the buggy code presented often has multiple problems. A future reader may have one or two of those problems with their code, but it's unlikely that they'll have all of them.

So merely dumping some code and saying "it doesn't work" is unlikely to be well-received. If your code has multiple problems, try to break it up so you can isolate each problem into its own MCVE. And if you state the problem with your code clearly and carefully, and supply all the information that potential answerers need to tackle the problem (the MCVE code itself, typical input, current output, and expected output, all properly formatted), then it may be beneficial to others with a similar problem.

Quite often in the process of creating one or more MCVEs you will discover for yourself what's causing the problem, or at least give you some clues as to what's going wrong. Putting the information that you've discovered in this process into your question can help readers to understand the problem; it also lets them know what you've already done in your attempt to fix the problem yourself. And questions where it's clear that the OP has done some research on their problem are always better received than those that show no research effort.

3

In addition to the great answers above, what also might help you in writing a good question is this simple exercise:

  1. Forget what you know about your issue and
  2. Imagine that YOU found this question on SO

  3. Would YOU be able to help given just the information from the question and no other knowledge of the problem?

  4. Would you, by reading this:

The issue is that for xbar[l]***, l no longer corresponds to the index.

be able to tell what exactly is the problem? If not, you know that your question lacks vital information.

  1. Think what would you need to know to debug the problem if you saw it on SO, then provide that information in your actual question.

Some things about your issue are obvious to you, but to others, without your "insiders' knowledge" of the problem, it's difficult/impossible to help.

2

If I may add, check the scientific method as a good debugging is based on it.

  • Ask a Question: It's not working why ?
  • Construct a Hypothesis: Where in the code it's not working and how can I modify it to make it works.
  • Test Your Hypothesis: Try the modification and see what's the result.
  • Analyze Your Data and Draw a Conclusion: What's was the output of your modification and how does it changed since your last hypothesis.

With the last step, you will get other hypothesis to work on until you get to your solution.

You must log in to answer this question.

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