40

We sometimes get downvoted on Stack Overflow by posting one-liner, working answers to some users with a very clear problem, like here.

So, OK, we're not a code-writing service, but what about the bad questions where the user provides a "wall of code", or just keywords gathered together to make us believe he actually attempted something (a bit like the blurb people put after their broken code to fool the free text/code ratio)?

I don't say I'm going to upvote those questions. But when the user says:

I have A and I want B

and the relation from A to B is clear enough, and if the answer can be 1 or 2 lines of good, explained, code, I don't see the problem.

So do questions have to provide some code, even the worst ever written or barely relevant, when the OP is just lost and wants guidance, especially if this guidance doesn't take us more than 5 minutes (we have jobs!)?

8
  • 32
    What's most important of all is that the OP shows he's put some effort into trying to solve the problem.
    – Cerbrus
    Commented Nov 30, 2016 at 14:18
  • 4
    And about effort: related answer which lead me to think that neither of your options can give good questions, both gives bad questions
    – Tensibai
    Commented Nov 30, 2016 at 14:27
  • 9
    @Cerbrus Is it? I thought SO was supposed to be a communal resource to provide answers to programming questions. If the site is deluged with cruddy questions, it won't make me feel any better to hear that the questioners were diligent hard-workers. And if I have a valid, legitimate question, I don't want to find out that the last person to ask got no answers because he didn't put enough effort into showing his workings. Commented Dec 2, 2016 at 10:34
  • 3
    Yes, it's good to see an indication of effort from the OP, but more importantly (IMHO) showing code helps us to understand why the OP can't figure out a solution for themself, as Ilmari Karonen's answer mentions. FWIW, Jean-François posted his answer not long after the comment was posted on the question requesting that the OP show some code. It can be rather annoying to post such a comment and then see FGITW answers start to appear before the OP has a chance to respond to the comment.
    – PM 2Ring
    Commented Dec 2, 2016 at 10:40
  • 2
    @BenAaronson: SO is not a place to just dump any problem anyone runs into. The effort I'm talking about includes debugging, searching for answers, things like that. If the OP hasn't done any of that, there's a good chance the question can be closed as "Too Broad" or "Unclear", as the OP may not even be aware of what he's actually asking.
    – Cerbrus
    Commented Dec 2, 2016 at 10:41
  • 13
    Completely untrue that the "most important of all" is showing effort. There are at least 10 things more important than that, including comprehensibility, reasonable scope, grammar/spelling, tagging, etc. Most of the time, the reason we want someone to show effort is to help limit the scope of the question and direct our answers, because it is just not possible for us to fully implement a major feature in a Stack Overflow answer. But otherwise, it is quite unimportant that someone shows us a broken code snippet for implementing something that is minor and reasonably scoped. We ain't yo momma.
    – Cody Gray Mod
    Commented Dec 2, 2016 at 17:04
  • 2
    I ignored the "what have you tried" comment because the question was answerable as-is, and I suspected that my reply wouldn't have anything to do with the failed attempt. In such basic pure python questions it is often the case (not the ones involving external modules, interactions with the OS, ...). What annoys me the most is when people answer and someone posted a "possible duplicate of". I forbid myself to answer in that case (except if it's a false alarm) Commented Dec 2, 2016 at 17:38
  • It's actually really difficult to come up with a credible but unfixable/irrelevant attempt. Just show sufficient research. Can't be that difficult. Commented Dec 3, 2016 at 14:37

3 Answers 3

92

Only debugging style questions explicitly require code.

I would like to take this chance to correct a common misconception.

If a user has code that doesn't work, and they are asking us why their code doesn't work and how to fix it, they must include a Minimal, Complete, and Verifiable example for their question to be on-topic.

Non-debugging style questions are less likely to be too broad or unclear if they do include a code sample (even pseudo code) that demonstrates their intent; but not including a code sample doesn't make the question off-topic by itself.

If you're closing questions solely because they don't contain code, you're doing it wrong


Everyone likes numbers, right?

These numbers were current when I wrote this answer. These statistics do not include deleted questions, but the point of this is not to say that questions which don't contain code are all inherently good questions, but rather that questions which don't contain code are not all inherently bad.

There are currently 12,882,683 questions on Stack Overflow, of which

Based on this we can see that a sizeable portion of questions do not contain code, most of which are not closed, and a reasonable amount of them are well received.

Take a look at the first link above and you'll find that a large number of these codeless questions have proven to be extremely useful.


You are asking the wrong question.

What's better: a question with no attempt or with an unfixable/irrelevant attempt?

As "better" is ambiguous, I'm going to replace it with "more useful", which is what I think you mean.

Questions can have varying degrees of usefulness regardless of whether or not they contain code. That said, quality, usefulness, and research effort have no pertinence to close voting; that is what up and down votes are for.

  • If a question shows a lack of research effort, is unclear or not useful, it should be downvoted.
  • If a question shows research effort, is clear and useful, it should be upvoted.

Is the question on-topic and answerable in its current state?

This is the question you should be asking yourself whenever you're contemplating the closure of a question, regardless of whether or not the question contains code.

  • If the answer is no and there is an applicable close reason, vote to close it!
  • If the answer is yes, answer it! 1
  • If you can improve the relevance or usefulness of a post without changing the meaning, edit it! 2

If the question is a programming question, on-topic, and not answerable in its current state, but does not fit the criteria for any of the existing close reasons, don't worry about it.

The whole point of closure is to prevent questions from receiving answers. So if the question is truly unanswerable, it isn't going to be receiving answers, and we don't need to spend any of the limited number of close votes we have in a day on them.

The roomba will clean them up eventually, and there is a seemingly endless supply3 of questions that are much more worthy of your precious few close votes.

If you need to bend a close reason to fit the question in order to justify closure, the closure isn't really justified.

Who knows? At some point in the future it might actually be answerable, or someone else may see something that you don't. If it does receive a useful answer, even better! Not closing it means that you didn't prevent it from receiving that answer.

You saved the day by doing nothing at all, and you had one more precious close vote to spend that day. It's a win-win!


1: If the question is a duplicate, you should not answer the question, and instead vote to close it as a duplicate.
2: If you are going to edit, make sure your edits are substantive
3: The Close Vote Queue is big. Really big. You just won't believe how vastly, hugely, mind-bogglingly big it is. I mean, you may think it's a long way down the road to the end of any other queue, but that's just peanuts to The Close Vote Queue.4
4: Paraphrasing a quote from Douglas Adam's The Hitchhiker's Guide To The Galaxy

5
  • 12
    Totally agree. People see questions without code and too often it is assumed to be offtopic. Many of these questions are a great resource on the site and definitely on topic
    – user3956566
    Commented Dec 2, 2016 at 1:38
  • 4
    Other answers are good, but that one is truly documented & excellent. I'll keep all this as a reference to non-code questions downvoters. If you can answer and it's not an obvious duplicate, answer it! Commented Dec 2, 2016 at 6:30
  • 6
    No, I hate numbers. But I like this answer!
    – Cody Gray Mod
    Commented Dec 2, 2016 at 17:04
  • The total opposite of Tiny numbers: 3,336,732 (25%) contain no code at all. 3,130,716 (94%) are not closed. 1,614,987 (52%) are zero or negative scored.
    – Braiam
    Commented Dec 2, 2016 at 17:21
  • 3
    @Braiam 223,953 of 3,338,044 no code questions (7%) have a negative score
    – user4639281
    Commented Dec 2, 2016 at 17:39
20

You seem to be asking two unrelated questions here:

"What's better: a question with no attempt or with an unfixable/irrelevant attempt?"

If the code posted by the OP is indeed a genuine attempt to solve the problem, then it is useful even if it's completely hopeless and misguided, since it illustrates the nature and extent of the OP's confusion, and thus hopefully allows answers to be written for their level of understanding (or lack of it), and in a way that hopefully clears any specific misconceptions that may be evident from their earlier attempts.

On the other hand, if the "attempt" posted by the OP is just a copy-paste from an external source, or something totally unrelated and clearly posted just to make it look like they've attempted something when they actually haven't and just want "teh codez", then it's worse than useless. The only way in which such "attempted solutions" are useful is that they make it clear that the OP is deliberately abusing the site as a free code-writing service, as opposed to a source of learning, and that we should simply downvote and close their questions instead of trying to answer them.

"We sometimes get downvoted on Stack Overflow by posting one-liners working answers to some users with a very clear problem [...]"

Do you really think the OP will understand how your one-liner works, and will be able to apply the same method the next time they encounter a similar problem, given the level of expertise (or lack thereof) they've demonstrated in their question? Do you also think that other people who may find the same Q&A thread on Google will understand how to apply your answer to their own problem?

If yes, then great, keep up the good work!

If not, you've just handed the OP a free fish, instead of teaching them (or anyone else) how to catch their own fish. Please consider at least adding a bit of explanation to your answer, if not to help the OP (who may not care, as long as they have a working piece of code that they can copy-paste), then at least to help others who may later stumble across your answer too and want to adapt it to their own related problem.

If you don't feel you have the time to do that, please consider whether you really have time to answer the question properly at all, or whether you should just leave it for someone else to answer. (Yes, if it's a halfway decent question, someone else almost surely will.)

In any case, none of this depends in any way on whether the OP provided any code (whether relevant or not) in their question, except insofar as that may indirectly provide some hints about their general level of knowledge and willingness to learn.

6
  • of course, posting code without any explanation is useless. I see your point. It's just that sometimes, people punish answers by a downvote whereas it works and is useful, maybe not for OP which may not have the skills to understand it / reuse it in another context, but for other more skilled people. You can also refrain from down/up/voting and leave it as is. thanks. Commented Nov 30, 2016 at 15:51
  • 6
    @Jean-FrançoisFabre You may choose to refrain from voting when you see an answer that is clearly not a useful answer to the question, due to, for example, a lack of clarifying meaning that those looking for an answer to the question would never understand it, but your decision to not vote based on the usefulness of a post (the described metric by which one is supposed to determine whether a post merits an upvote or a downvote) doesn't mean others shouldn't use the voting tools correctly to provide accurate and valuable feedback on the usefulness of an answer.
    – Servy
    Commented Nov 30, 2016 at 15:59
  • 6
    @Jean-FrançoisFabre: Some people will downvote all answers to questions that they deem to be sufficiently bad, on the principle that such questions should have been closed and not rewarded with an answer at all. Whether this is a good or a bad thing to do is a broader and more contentious topic, but IME the best way to avoid your answer being downvoted for such reasons (besides, of course, just not answering crap questions that are about to be closed) is to write your answer in such a way that it's clearly helpful also to people other than the OP who may stumble across it. Commented Nov 30, 2016 at 16:12
  • 2
    [...] If you feel like it, you may even consider taking the time to edit the question to look more like the way the OP should've asked it, e.g. by picking a good, searchable and informative title, fixing any obvious spelling and grammar errors, and removing any unnecessary elements (like greetings and thanks, irrelevant background details, and, yes, any truly misguided and overly verbose solution attempts) that are of no use to anyone finding the question later on Google. Commented Nov 30, 2016 at 16:12
  • thanks for all your comments and for not downvoting my meta-question :) Commented Nov 30, 2016 at 16:19
  • 1
    I wish I could give you another upvote, just for that 1st paragraph. :) Sure, a relevant code snippet indicates that the OP has a made a genuine effort, but I'm mainly interested in seeing their code to get an idea of their thought processes, and to reveal the misunderstanding or lack of language knowledge that has led them to not being able to solve the problem themself.
    – PM 2Ring
    Commented Dec 2, 2016 at 10:35
10

Much of the purpose of the provided snippet is to

  1. Make the question clearer; a demonstration of what they're trying to do will often aid the written description in clarifying what they want. A question with a good faith attempt is notably less likely to actually be closed as Unclear.

  2. Help to give readers an idea of what they do and don't understand about the topic, so that you can explain just what they need to know, rather than everything about a situation. Very often this is the difference between a question that's Too Broad and one that's not.

So given this, if the OP provides a snippet that is worthless, in that it's either unrelated to what they actually want, just a stubbed out public API with no implementation, or just so completely hopeless that it's clear they lack many core tools that they would need to solve this problem, then such an example isn't fulfilling either of the two above goals. Such a poor code snippet is unlikely to successfully clarify the question, meaning that the written description of what's needed needs to be very on point, and it's often a strong indication that the question is Too Broad, because the author apparently needs a lot explained to them in order for them to understand an answer to the question.

So to answer your actual question of, "what's better", well, the included example is often better, insofar as it makes it clear to a reader of the question that the question is probably close worthy. It doesn't actually make the question a better question in terms of the ability to provide a quality answer, in the vast majority of cases.

8
  • 8
    There's only one "better" here, not two: is the question reasonably answerable?
    – Robert Harvey Mod
    Commented Nov 30, 2016 at 15:49
  • yes, the question was answerable, code or not. No guesswork involved. In that case, I take my chances. Commented Nov 30, 2016 at 15:51
  • 1
    @RobertHarvey If you only care about posting answers, then by all means, skip the portions of my answer that don't relate to it. If you're interested in trying to improve a problematic question, or determining what moderation actions may or may not be appropriate for a question (something I'd think a moderator may be interested in) then the rest of the answer is relevant.
    – Servy
    Commented Nov 30, 2016 at 15:55
  • 2
    I have a diamond, so yeah, I care about moderation. But I don't go through mental gyrations like this when evaluating a flagged question, and neither (IMNSHO) should anyone else have to.
    – Robert Harvey Mod
    Commented Nov 30, 2016 at 15:56
  • 2
    @RobertHarvey I'm almost certain that you do though; perhaps not as explicitly, or even, given the amount of experience you have with it, consciously, but I'm sure you pay attention to whether a question is unclear or Too Broad, and I'm sure you take code snippets provided into consideration when trying to make sense of an unclear question, or determine the actual scope needed to provide a quality answer to a question (to then judge whether that scope is too large). I'm just spelling it out more explicitly for those that don't have the experience to do that instinctively.
    – Servy
    Commented Nov 30, 2016 at 16:02
  • 5
    Fair enough. Personally, I think it's simpler than this: a bad snippet (unless you're asking a code troubleshooting question) is worse than no snippet at all, even for those folks for whom "showing effort" is still a thing. I've seen folks paste code into questions that's seemingly unrelated to the question, just so they can "show effort."
    – Robert Harvey Mod
    Commented Nov 30, 2016 at 16:06
  • 2
    In code requesting questions, I often think what OP requests is far more critical than whether they have "show effort" in terms of usefulness of question
    – ggrr
    Commented Dec 1, 2016 at 2:48
  • @amuse Note that this answer never uses the word "effort" in it.
    – Servy
    Commented Dec 1, 2016 at 14:08

You must log in to answer this question.

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