56

Quite often, especially with the tag 'java', I have come across questions that contain a code snippet followed by "How does this code work?" or "What is this code doing?" or sometimes even an implicit query stated as "I don't understand what this code is doing."

How should such questions be dealt with? I feel that they are off-topic, but I am not sure if they should be flagged. If yes, then what should the reason be?


After a little more scouting, I discovered a potential reason for flagging questions of this type: as stated in the tour, Stack Exchange is a network of Q&A sites, not help forums.

3
  • 5
    Related: “Explain X to me” questions: How to react? Commented Dec 11, 2014 at 16:43
  • 1
    So, this was my question yesterday: stackoverflow.com/questions/27411450/… and I hesitated to post it for all the stated reasons... but people were very helpful and I learned quite a bit from it. I was surprised to get upvotes. Was it acceptable? Commented Dec 11, 2014 at 17:01
  • @thumbtackthief Personally, I think the question was a good one if you got answers from it that helped you. I often get a great answer to a question right before someone closes it. I often get upvotes to my questions right before they get closed. But then it doesn't matter anymore because one good Samaritan saw the merit in my question and took the time to stop and help, even when others thought the question unworthy. Commented Feb 17, 2021 at 23:52

2 Answers 2

99

I vote to close such questions as Too broad.

Without very specific focus on one aspect of the code (e.g. what does the .frobnar() method call do here?), it is not clear what the OP wants explained, and you can easily end up explaining how electrons in computers end up executing the code presented, with every abstraction level in between.

9
  • 2
    Agreed. I sometimes add a comment to suggest stepping through the code with a debugger.
    – Zéychin
    Commented Dec 9, 2014 at 15:25
  • 5
    And also down voting if it shows no research. Commented Dec 9, 2014 at 17:40
  • 6
    I'd say these fall somewhere in between "Unclear" and "Broad". One important point is that the question really must explain what its asker does understand about the situation in order to be answerable. jmac's Puzzle Analogy may be useful reading here.
    – jscs
    Commented Dec 9, 2014 at 19:28
  • 28
    Okay...but how do electrons end up executing code....
    – rene
    Commented Dec 9, 2014 at 21:22
  • 1
    @Zéychin Those kinds of comments IMO are noise. Yes, everybody should know how to use a debugger, but saying "step through the debugger" doesn't convey any information whatsoever. It's akin to "google it".
    – user3920237
    Commented Dec 9, 2014 at 21:38
  • 8
    @remyabel Of course, discretion is used. If it is, in fact, a simple algorithm and the person appears new to software, I'll suggest it, as the person may well not know that debuggers even exist, much less how to use them, which I would argue conveys the idea of the next step for the OP, even if the SO community does not support the question. Giving a man a fish versus teaching a man to fish and all that jazz.
    – Zéychin
    Commented Dec 9, 2014 at 21:47
  • 3
    The problem is that "I don't understand" is a statement, not a question. Naturally, it wouldn't be constructive, or it might well seem rude, to use that wording in a comment, but advice should be focused on requesting a specific question.
    – Nick Cox
    Commented Dec 10, 2014 at 10:43
  • 2
    @NickCox: we tolerate plenty of questions that don't have an actual question in the text (in the grammatical sense). Posts that contain only statements, leaving the question implied are not by definition a problem. Adding Can someone explain this to me? would not make it any better here. Commented Dec 10, 2014 at 10:52
  • 1
    @MartijnPieters Quite so. I did say "specific". As you imply, the precise grammar of a posting is immaterial; it's whether there's something that can be answered with confidence that it addresses the expressed problem.
    – Nick Cox
    Commented Dec 10, 2014 at 10:58
-4

I'm not sure if closing as too broad is useful for Stack Overflow and the OP. The OP might be upset and dind't learn anything. This will just result in additional, perhaps a little bit better questions which Stack Overflow has to deal with.

I think the better way of handling such questions would be a generic Community Wiki question and answer to the question "I don't understand how this code works".

The answer should

  • give some instructions on reading the code
  • give directions to start learning how to use a debugger
  • give some instructions for refactoring the code to clean code so that it can be understood
  • ...

We could then mark the OP's question as duplicate, so he is redirected to at least some useful input, the OP is not upset with the negativeness of Stack Overflow and hopefully he will ask much better questions in the future.

I consider this generic question as on-topic, because

  • using a debugger is essential for programming
  • reading code is necessary for programming

Since it is a Community Wiki answer, it can handle the "too broad"ness of the question.

4
  • 4
    This is a generally good idea. Until the OP whines that the CW doesn't answer their question, and their question isn't a duplicate, and we should address their specific question. Kudos for the idea, but I see it backfiring for this particular case. If we do close the questions as unclear, at least we can tell them what they need to add or change to get their question to be reopened. Closing a question isn't the end of it- It can be reopened. :)
    – Kendra
    Commented Dec 11, 2014 at 15:41
  • 24
    There are 7 billion people on the planet earth. We do not need all of them on stack overflow. Making people feel that their questions are not acceptable is a good idea if their questions are not acceptable, even if it makes them feel like stack overflow did not answer their question. The asker of a poor question would only become an asker of a better question through happenstance or poor question exhaustion with the above system, and the well of poor questions is bottomless... Commented Dec 11, 2014 at 15:55
  • 1
    @Thomas: The idea of a redirection to a wiki question with high-level instructions on debugger use and understanding the code flow is an excellent suggestion! Commented Dec 11, 2014 at 22:18
  • @Yakk: I agree, SO doesn't need 7 billion people. But we already have the one that asked the question, don't we? Commented Dec 12, 2014 at 7:49

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