63

If a competent coder asks a "spot the bug" question where the answer is non trivial, should it be downvoted? Does it depend on additional factors like the question's appeal to others?

Suppose such a question where it is a just a copy/paste of a piece of code and it turns out the bug is extremely twisted, detected only by expert eyes, but the context is so specific that it will be of service to almost no one else. What's SO's attitude towards this sort of thing?

8
  • 9
    The key here is "where the answer is non trivial" uncommon logic issues for example don't always get downvoted. Something that is trivial for you now may not have been 2 years ago.
    – Kevin B
    Commented May 6, 2014 at 22:22
  • @KevinB So appeal should be irrelevant?
    – schmop
    Commented May 6, 2014 at 22:24
  • 1
    This is all opinion anyway since downvotes are subject to your own definition of usefullness/clarity. Whether or not it should be closed is another topic entirely, but i don't see that referenced in your question.
    – Kevin B
    Commented May 6, 2014 at 22:25
  • Yes, I think appeal should be irrelevant, however, if the question didn't appeal to me, I wouldn't open it to begin with.
    – Kevin B
    Commented May 6, 2014 at 22:30
  • 1
    Bugspotting, if requested without acceptable minimal example, or with an example which can't be compiled or is incomplete (e.g. assumes that there's a context, like a knowledge of IDE/SDK) - clearly not fits a SO format well. There are forums, mailing lists and private chats ready for that kind of questions.
    – kagali-san
    Commented May 7, 2014 at 9:50
  • 22
    I submit these "Spot the bug" type questions all the time and never get downvoted for them. Why? Because I explain the steps I've already taken to try to resolve the issue, I include relevant information regarding device, application purpose, expected results, and any errors I'm getting. If it turned out to be something petty, everyone knows I've already spent exhaustive time on it and no one feels the need to punish me for a legitimate mistake. Sometimes, a fresh pair of eyes will spot a simple mistake you can't see anymore... Commented May 8, 2014 at 9:03
  • @JRadtheBad This also means that in principle every "fix my code" question can be brought to a level where it either solves itself by the authors efforts or is in a format that it fullfills all the requirements of the top voted answer here. It's just a matter how much effort is put into it. I would even say that the majority of questions on SO all fall into either "what is the best way to do.." or "what is wrong with my code" or "how can I.." categories. Commented May 12, 2014 at 12:41
  • 1
    What's the point of this question? Of course there are legitimate "spot the bug" questions. Many questions that contain code could be put in this category -- if there weren't some problem with the code, the OP wouldn't need to include code in the first place. The difference between good and bad questions lies in the other information provided and in OP expectations: "solve this for me" is bad, "here's what I've done, here's where I think I'm stuck, what am I missing" is much better. Vote up or down to encourage the latter and discourage the former.
    – Caleb
    Commented May 12, 2014 at 14:07

4 Answers 4

134

Legitimate code troubleshooting questions will contain all of the following:

  • A brief, but specific statement of the problem, telling us precisely what is wrong. "It doesn't work" is not a problem statement.

  • A brief code snippet that reproduces the problem.

  • The exact wording of the error message you are getting, and which line of code is causing it.

  • The desired behavior; what the program is supposed to do.

  • The troubleshooting steps you've attempted so far to isolate the problem.

  • A meaningful title. Don't put your Google Search in the title. Don't say in the title "How do I Foo the Bar" if your question is about "how do I fix [this error message] while fooing the bar?"

Questions missing one or more of these things are subject to closure as "insufficient information to diagnose problem."

Questions containing only a code dump with no explanation of the problem, no attempt at troubleshooting yourself, and containing the inscription "How do I fix my code," are specifically off-topic.

Further Reading
How to Debug Small Programs by Eric Lippert
How to create a Minimal, Complete, and Verifiable example

10
  • How do you suggest one should title such a question? It's usually fairly hard.
    – dfeuer
    Commented May 7, 2014 at 9:27
  • 6
    OP almost by definition can't decide which parts of a traceback might be relevant. The full traceback should be posted if any. We have scrolling to avoid it to take too much space. And the person who is capable to answer the question is also capable to skip irrelevant parts in the traceback, the person who asks the question might not. At least, in Python tracebacks may provide information about what python version is used, what libraries are used, what versions, what lines caused the error: it is often enough to understand what happened even without looking at OP's code.
    – jfs
    Commented May 7, 2014 at 10:18
  • @RobertHarvey the google search ones make it super easy to find duplicates. Also titles like "Java Problem" and "Java crashing" are obviously bad (though I think problem is restricted in titles now) Commented May 7, 2014 at 16:26
  • 2
    My answer doesn't explain how to write bad questions, @Marshall. I think the new folks are already good enough at that. :)
    – Robert Harvey Mod
    Commented May 7, 2014 at 16:27
  • 1
    They need hand holding with everything else, so I wouldn't be so sure Commented May 7, 2014 at 16:27
  • 2
    @MarshallTigerus: What they need is closing and downvoting. Quickly.
    – Robert Harvey Mod
    Commented May 7, 2014 at 16:29
  • @RobertHarvey how about a checklist then. When you flag to close, you can click "bad code troubleshooting" or something and select all the things it doesn't have. The OP can then see what he is missing, fix the question, and it can be reopened Commented May 7, 2014 at 16:31
  • When the problem is incorrect behavior, as opposed to error messages, titles can be particularly difficult.
    – dfeuer
    Commented May 7, 2014 at 16:38
  • @dfeuer: As long as "How do I [do something]" or a Google Search is not in the title, I don't really care what's there. There's nothing more infuriating than googling "How do I Foo the Bar in C," only to stumble across a highly-localized troubleshooting question.
    – Robert Harvey Mod
    Commented May 7, 2014 at 16:44
  • 1
    I like this response. Half the time, in paring down my code to be the bare minimum required to make it break, I discover the cause of my problem before even submitting! The times that I don't, means that there is some fundamental issue with my code that I can't find a solution to online, and the answer may be useful to someone else, rather than being entirely specific to my implementation.
    – Ross Aiken
    Commented May 9, 2014 at 16:17
32

I personally am unimpressed if people haven't reduced their code to a minimal example to show the unexpected behavior. In my opinion this is an important step in debugging. If people haven't taken the time to go through these steps themselves i don't feel its reasonable to expect others to do this for you.

In addition questions with too much code in them often act as a false oracle to search engines which means others searching will get pointed to un-useful questions more often.

I think such questions should be closed.

I think if you have reduced your problem to a minimal example and still have unexpected behavior (your bug) then the the answers may well be helpful to others who make similar assumptions and is hence a good question.

6
  • 10
    +1 for minimal example. Too many codes are way too long for what is asked. Commented May 8, 2014 at 12:14
  • 2
    -1 for minimal example. Heck, examples are not to be trusted. 3/4 of the posts I make are for Haskell code, whose bugs cannot be reproduced, because the bugs are type errors and if I understood the type error well enough to reproduce it in a minimal example, I wouldn't need help. But the error message and a good fragment of code is good enough for somebody who knows what is going on.
    – nomen
    Commented May 8, 2014 at 23:42
  • 6
    @nomen thats exactly the point if you took the time to reduce your problem to a minimal example you would probably: 1. solve your problem, 2. learn something, 3. produce a question thats helpful to others. SO isnt a debugger its a place to go where experts can answer questions for the benefit of everyone not just the OP
    – undefined
    Commented May 8, 2014 at 23:47
  • That's not a very good point, then. My point is that I can force the compiler to make the same error message. But not necessarily for the same reason. Some errors are not reproducible without actually knowing what is causing the error. Never mind issues where a minimal example still requires thousands of lines of code, because of all the libraries and classes in play.
    – nomen
    Commented May 8, 2014 at 23:59
  • 1
    @nomen would such a specific question ever be helpful to anyone but the OP?
    – undefined
    Commented May 9, 2014 at 0:17
  • @Luke: the answer could be. For example, check out stackoverflow.com/questions/23414963/… . There are at least 4 classes of ways a "non-injective type" error could be introduced. I knew about three of them until somebody read the error message and broke it down for me.
    – nomen
    Commented May 9, 2014 at 0:21
10

Most of this type of questions are not interesting for anyone else but the OP.

Even if someone made the same mistake it is very unlikely that a search will find this particular question.

The only way to save such a question is by changing the title and content after having found the solution.

There are a gazillion questions in that boil down to: did you implement INotifyPropertyChanged (correctly). But hardly any question would state "how to implement INotifyPropertyChanged?" but rather "DataBinding is not working" or, worse, "property not updating".

I prefer people to show their code somewhere else and ask questions here "How does databinding work?"

3
  • 7
    All true. And yet, here we are. A site that consists mostly of troubleshooting questions. The way to fix the INotifyPropertyChanged questions is to write a canonical/reference question, and close the "did you implement INotifyPropertyChanged" questions as duplicates of the canonical/reference question.
    – Robert Harvey Mod
    Commented May 7, 2014 at 16:56
  • Counterpoint: if as the question supposes, the bug is one that a competent coder wasn't able to diagnose and fix for themselves, and the solution is non-trivial, then the Q&A is interesting since it contains knowledge that at least some competent coders do not have, but would benefit from acquiring. I would expect the answer in that case to involve an explanation of some more general concept, compared to an answer like "you misspelled this variable name/you missed a parenthesis/the docs for this function say it does this" which all competent coders would be able to solve for themselves.
    – kaya3
    Commented Jan 7, 2023 at 10:26
  • 1
    @kaya3 - I agree that it might be a very interesting and valuable answer. For me, the main problem is: "Even if someone made the same mistake it is very unlikely that a search will find this particular question", so the value to the site and the chances that this answer will be found/read are very low.
    – Emond
    Commented Jan 8, 2023 at 10:55
3

The issue with such questions

If a competent coder asks a "spot the bug" question where the answer is non trivial, should it be downvoted?

I wish to challenge the premise. A competent coder by definition cannot ask such a question, except by a deliberate refusal to engage in the process of coding competently.

Competence at coding entails writing code deliberately and with a specific intent in mind, which entails having in mind - or at least being able to come up with one on demand - an expected result and behaviour for each individual step of the code that was written.

When code results in an explicit, unhandled error (rather than simply a wrong result), competence at coding entails an attempt to read and understand the error message, relate it to the code, and thus pinpoint a step with unexpected behaviour (since the actual result is inherently not expected or desirable). It also entails being able to work backwards in order to verify the input and initial state at the point where the error occurs; either it's expected, in which case we have a question about why this input results in an error, or it's unexpected, in which case we actually have an ordinary unexpected-result question about the previous step. (Or, possibly, some step before that; "garbage in, garbage out", after all.)

Spotting the bug is, definitionally, the process of looking through those steps to identify where the result differs from expectation.

A proper "debugging question" for Stack Overflow is one which:

  • Does not need more focus: i.e., there is a specific step in the process that has been identified to cause a problem (it could be that there is more than one problem in the original code; but the OP is expected to ask one question at a time);

  • Does not need debugging details: i.e., there is a Minimal Reproducible Example for that step - i.e., short-cutting past previous steps to supply problematic input at the point where it causes a problem, and skipping subsequent steps (otherwise, it "needs debugging details");

  • Does not need details or clarity: i.e., it explicitly states an expectation for the step (for bonus points, include reasoning for expecting that result, so that any underlying misconception can be addressed head-on); shows what happens instead; and asks why the result differs from expectation (ideally, actually starting with the word "Why" and ending with "?");

  • is not a duplicate (of course).

In other words: a proper debugging question is not a debugging question any more, because it is not a "where" question - it is a why question, about the unexpected result in the identified and isolated step.

Justifying Stack Overflow's standards

As I re-state at every possible opportunity, Stack Overflow is not a discussion forum. As such, answering questions here is not about helping the person who asked to solve a coding problem, but instead about publishing knowledge in Q&A format for a broad audience.

To communicate knowledge effectively in the Q&A format, the Qs really do need to be as high quality as possible. For questions about code behaviour (i.e., not "how-to" questions), a proper, truly minimal MRE is necessary because:

  • By focusing on one question, it becomes possible for others (who have done the same work - otherwise, they have no hope of finding anything; if a search engine could debug code for you, there would be no use for Stack Overflow!) to find the question, and ensures that everyone who answers is on the same page, without getting sidetracked by irrelevant details;

  • By skipping irrelevant steps, it avoids the risk of distracting people who are answering the question (even if there aren't actual problems, it risks turning the site into codereview.SE) and wasting the time of people who search for the question later;

  • By explicitly stating expected and actual behaviour and asking a question, it becomes possible for others to find the question (i.e., a proper title for the question will make itself obvious) and to recognize the question once found;

  • By doing all of these things, it becomes considerably easier to recognize duplicates and vastly easier to justify duplicate closures, and linking duplicates improves everyone's experience by making it possible to put canonical information in one place.

"But it's hard!"

There's one objection I want to preempt here: the notion that debugging is hard. Well, yes. That's well known. That's why you aren't supposed to write clever, complex code. This topic is so thoroughly covered in the literature - going at least as far back as Kernighan - that "coders" who wish to consider themselves "competent" have no excuse. The standard for competence includes:

  • Using version control properly, so that it's evident when things stop working and therefore what changed to make them not work;

  • Paying attention to any code that comes from an external source (including Stack Overflow!), in order to understand and adapt it before inclusion rather than copying and pasting willy-nilly;

  • Keeping code aggressively refactored so that components can be tested and problematic ones can be more easily isolated to create MREs;

  • Testing the code so that problems are noticed as soon as possible after they arise - ideally using automated testing systems, at a complexity scale appropriate to the code base.

Yes, of course beginners are not competent by this standard (or any reasonable standard). So it goes in any field, more or less by definition. Programming has a problem in that novices are allowed to write far too much code without any conscious effort to build the skills of competence.

But that doesn't change the standard - again, just like with any field. If you had a gym with a bunch of kids who had worked their way up to a 225 lb (100 kg) deadlift without any instruction beyond "just pick the weight off the ground, dummy", and they started hurting themselves, the blame would lie with their coach (or the gym) for letting them pull the weight without guidance or form checks. It would not lie with the field of kinesiology for coming up with "unreasonable" form-check standards or dogma about stance and posture.

As I would tell students: "if you think I'm demanding, strict, and cold - wait until you meet the compiler".

2
  • I hard-disagree with this. For example, you can be a competent Python programmer without knowing that the list constructor can suppress exceptions in very specific circumstances even though the documentation says nothing about this. A competent programmer can therefore have a program which does the wrong thing for a reason they don't understand, even after doing everything they are supposed to to figure out the issue themselves.
    – kaya3
    Commented Jan 7, 2023 at 10:45
  • 1
    My point is about discovering that the list constructor has suppressed an exception. Or at least, discovering that something happened that was contrary to expectation, during the process of creating the list. Commented Jan 7, 2023 at 17:02

You must log in to answer this question.

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