I have read this: Why do you cast downvotes on answers? and tried searching for a specific view on this scenario but cannot find. If there is a question covering this already I apologize.

Q: Would you downvote a "code only" answer, where the code works as given but has no explanation as to how/why it could work with regards the question?

  • 1
    may be because it is not guarantee that who has given the answer actually owns it. It may be a copy from net and answerer doesn't know what is going on the code just found on net and posted it.
    – Harry Joy
    Commented Jun 17, 2011 at 10:28
  • 1
    @HarryJoy That doesn't qualify it as a valid answer. Commented Jun 17, 2011 at 10:42
  • @Harry, hadn't even thought about that scenario, if that was the case that would make it worse :o
    – clairesuzy
    Commented Jun 17, 2011 at 10:59
  • 1
    @clairesuzy: that is the first case I got on mind.
    – Harry Joy
    Commented Jun 17, 2011 at 11:12
  • 4
    @Octavian - why isn't it a valid answer? It might not be one you like (and I'd agree with you) and it might be a weak answer but it's possible for it to be a perfectly valid answer.
    – Rob Moir
    Commented Jun 17, 2011 at 11:29
  • 1
    @RobertMoir I don't see how someone that does not understand the code he copy/pastes will be able to provide that code as an answer. Logically it does not make any sense. Commented Jun 17, 2011 at 11:33
  • 3
    @Octavian - I'd agree that its unlikely, but even a blind squirrel occasionally finds a nut.
    – Rob Moir
    Commented Jun 17, 2011 at 11:36
  • I may be completely off my tree but I did down vote eventually, even after saying I wouldn't .. the "code only" answer was not acknowledged or accepted (though it had the highest votes?) but as I said in comments when pressed for an answer the answerer refused to give an explanation. and is still arguing the fact why he or she should? So I just had to DV, last straw, so it seems circumstances are everything as a few of the replies here tell me :) thank you for your views they helped through watching a scenario unfold!
    – clairesuzy
    Commented Jun 17, 2011 at 23:38
  • 1
    Before you ask: Downvotes on Meta are different.
    – slhck
    Commented Jun 3, 2012 at 17:47
  • 2
    There are no "welcome gifts" or anything here. We assume everyone's read the FAQ and How to Answer. We generally don't vote differently for high reputation users or new users. Posts are supposed to be voted on based on their merits alone – regardless of how long you've been a member. Just try to make your answers stand out and explain a little. In the long run, this will get you more upvotes.
    – slhck
    Commented Jun 3, 2012 at 17:56
  • I'd vote to close this, since "code-only" is an ambiguous term that invites argumentation. A large vocal group of people are now using "code-only"in the non-standard way you've defined it: "the code works as given but has no explanation as to how/why it could work with regards the question" and they respond "yes, those suck, I certainly downvote those". Then a large enthusiastic second group of people jumped on the bandwagon with "yes, everyone knows code-only answers suck, I downvote them." Except they're using the word in the standard literal sense, and now causing damage to fine answers.
    – Don Hatch
    Commented Jan 30, 2016 at 11:13

11 Answers 11


Not by itself. This would depend on a couple of other factors I'd say:

  • Let's assume it is devoid of code comments too.
  • But is it readable code?
  • Is it self-explainatory or confusingly named?
  • Does it answer the question specifically (variable names) or is it a generic 08/15 code snippet from a manual.
  • Was the question just asking for a code fix, or did it deserve a textual explanation/advise?
  • Does it work anyway?

Otherwise it would fall in the same category as one-liners sans reasoning.

  • 1
    I'd emphasize specifics of the question as well. For example, a question clearly from someone new to programming or the language/paradigm will likely need an explanation, whereas someone clearly an experienced programmer may not need any more than the code snippet as they're able to figure your answer out on their own.
    – Servy
    Commented May 31, 2012 at 15:08
  • Good intelligent answer and criteria; I wish it were universally followed. I find it extremely insulting and disrespectful when someone downvotes due to some blind formula like "code-only => bad" without actually thinking about whether the answer is good or not, thereby requiring addition of fluff (which does make an answer worse) to satisfy them. That certainly makes the site worse.
    – Don Hatch
    Commented Aug 4, 2015 at 1:47

Seeing as there are so many other code-only answers in that question (and many similar ones), it indeed seems a bit unfair to single you out. (Edit: you weren't singled out after all - your answer was caught by the "review" tool because you're new.)

But the best thing to do is to just shrug it off, and go on. Votes aren't that important. Every SO user is free to cast them as they like - and they're all individuals from all over the world with varying views, opinions, and standards. We all receive downvotes occasionally, and we will not always agree with them - don't take them too seriously.

  • I didn't single him out, see my answer below. Commented Jun 3, 2012 at 17:57
  • @Manish yeah, I see. (The existence of other code-only answers on that question that didn't have downvotes made it look like you did, but I guess this was the review tool's "fault"...)
    – Pekka
    Commented Jun 3, 2012 at 17:58

The tooltip for downvoting says "this answer is not useful" and it's a pretty good standard to apply. Often "just code" answers aren't useful, or at best they could be a lot more useful with an explanation.

Code-only answers could almost always be improved by explaining what the code does, why you wrote it this way, why it solved the problem and so on. They are inherently not the best answer possible, even with the information you obviously know. Lack of effort and explanation are "encouraged" reasons for downvotes in my book..


I wouldn't downvote it. But neither would I really upvote it. There's nothing to 'punish' or inherently wrong there, so you don't have to to downvote.

  • that would normally be my way too, but an example is a bounty question where others have upvoted it, whereas there are answers (with less votes) that are correct for the scenario and have explanations
    – clairesuzy
    Commented Jun 17, 2011 at 10:56
  • @clairesuzy you could upvote the rest. Of course this isn't a hard and fast rule. I usually reserve DVs for something that is blatantly wrong. You could also leave a comment asking the user for an explanation before the DV
    – JohnP
    Commented Jun 17, 2011 at 10:58
  • true.. about the UV's -and in the answer, that prompted my question, someone has already asked the answerer for explanation, they replied "no, not unless asked someone asks" (they just did didn't they?) hehe anyway I'm not going to DV in this case as I have also now answered the question and it just might seem like sour grapes
    – clairesuzy
    Commented Jun 17, 2011 at 11:05

I, personally, have seen too many one-liner-code-only posts on SO, and I'm trying to fix that by downvote+commenting on bad posts. I don't single users out, they usually appear in /review/. I often handed out ~40 other such votes daily.

Basically, a code-only answer doesn't help other visitors learn. It doesn't help anyone learn. That doesn't make the Internet Better™, that just helps us degrade into a quick-fix forum.

Please write substantive answers.

Shameless self plug: Check out the other voting faq

  • This makes me sad. If you see a one-liner-code-only post that is not a good answer (i.e. it's really unclear and would really benefit from explanation-- or it's not substantive, as you say) then yes it deserves a downvote. But if you are downvoting merely based on the fact that it's code-only, I wish you wouldn't. That encourages people to add fluff to answers in order to avoid downvotes-- and that certainly makes the site worse IMO.
    – Don Hatch
    Commented Aug 4, 2015 at 1:46
  • @DonHatch I'm only talking about the answers which really could do with some extra info aside from the code (i.e. almost all of them). "code only + fluff" isn't something I encourage, and if people do it to avoid a downvote, they'll still get it. Commented Aug 4, 2015 at 19:59

Depends on the situation. For this question, I would definitely downvote a code-only answer.

  • 1
    haha.. so would I ;)
    – clairesuzy
    Commented Jun 17, 2011 at 11:08
codeOnly != badAnswer

Especially if the asker posted something along the lines of "What is the syntax to exit a loop?" etc.


  • 5
    Is that a new 4chan board, or an unnecessary regex? Commented Jun 17, 2011 at 17:09
  • @BoltClock, it would be unnecessary regex but it does more look like code than just No.
    – YOU
    Commented Jun 17, 2011 at 17:22

I do. I even flag those answers. A bunch of code is not a valid answer. At least a few lines of explanation is not too much to ask for.

A valid answer for me is something which does not only solve the problem but also explains the user why it solves the problem. The reason behind it is that I think we should not only share text but knowledge.


I don't remember downvoting code-only answers, but I'm inclined to do so now.

The reason is that the context of why the answer works would be shared only between the original poster and the answerer. A person reading the code snippet later, may have no idea as to why the answer is valid. Ok, granted there will be snippets that will not fall under the previous definition, but that is not the point.

The point is that, the answer is useless to anyone not knowing the subject very well. This is as good as going on ServerFault and providing a shell script that has rm -rf / to a novice with the adjoining line: "Run this!! This will solve your problem". Ok, most people would know that, but who would know drop table dual in the context of Oracle. In plain and simple words, the likelihood of an answer being verified by multiple people reduces with code snippets that are undocumented.

PS: The answers of type "Look at this link. The answer is here." should also fall under this category.


I will surely surely down-vote it!

Because if you are posting only a wall of code, though it works and OP just copies it and execute it and enjoys whooo!! the code works for him. OP was successful in coming out of his issue but what about his knowledge about why that issue was coming? What if he faces similar kind of issue next time.

I will also say that its because of "code only answers" many OP's are forced to ask similar question again many a times. Because OP has no clear idea about how the code in other answers work as they are without explanation!

So, it better to spend 5 mins, explaning the issue/problem/mistake that OP was doing in his code due to which he was not able to make it work!

You must log in to answer this question.

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