Here is a great example of this. Granted, that was that user's first post, but this is still common.

UPDATE: That example has since been updated, so consult the original version.

This type of answer isn't always favored on SO, either. Even if such answers may benefit the OP, it may not benefit visitors that don't fully understand the code and/or the specific context. I think this is even more detrimental for CR because the intent is to review, not simply to give (after all, we do not write code on demand, but we can at our discretion). For instance: if the question specifically asks for ways to simplify the code, not everyone may understand why (or if) this answer works. I wouldn't prefer to consider votes the only measure of validity, though. If that were the case, then anyone (that is, someone not experienced with that language) could think, "this definitely looks shorter!", and upvote it. What if it happens to be flawed (without criticism from more experienced users), and the answerer didn't "argue" his/her case in the form of an explanation and/or code comments?

Anyway, back to the issue at hand. Should this be a requirement? Specifically, should such posts receive comments telling the answerer to explain the code in some way? The voting is, of course, up to the individual, but I personally do not consider such an answer worthy of a downvote in and of itself.

  • \$\begingroup\$ Related discussion on Meta.SO: Is there any benefit to allowing code-only answers while blocking code-only questions? \$\endgroup\$
    – Bobby
    Sep 18, 2013 at 7:50
  • \$\begingroup\$ @Bobby: I anticipated this, but I figured it would be a slightly different case for here. That could still be part of this discussion. \$\endgroup\$
    – Jamal
    Sep 18, 2013 at 7:58
  • \$\begingroup\$ I think much that discussion is still relevant, especially the answer from CasperOne. \$\endgroup\$
    – Bobby
    Sep 18, 2013 at 8:14
  • \$\begingroup\$ @Bobby: Agreed, especially the closing statement. :-) \$\endgroup\$
    – Jamal
    Sep 18, 2013 at 8:17

2 Answers 2


My take on this is No, we should not allow such answers. Why?

We're doing Code Review here, so what does that mean?

Code review is systematic examination (often known as peer review) of computer source code. It is intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers' skills.

Quote from Wikipedia

The main point here is the last, we're all here to either improve someone's coding skill, or get improvements for our own. We're not here to improve code itself, but rather improve the programmer who wrote it. I think this is the most important and most significant difference.

If you want someone to improve in any way, you have to teach them. I'll not go into details on how teaching works, because I suck at it, but it includes a lot of words and explanations. With the Internet in it's text-only form we have the possibility to go into deep details and still allow the viewer to skip stuff s/he already knows. Meaning we can write long, detailed answers, and if the reader already knows about it, it can be skipped, but it's still there for the reader who does not know.

Back to code only answers, they're basically just dumping code and maybe improved the code itself, but it most likely does not teach the programmer something except on close and intense studying of said code. Additionally this might lead to a C&P culture, were a question is asked here, a code only answer is posted and OP simply copies that without learning anything.

There is one valid form of code only answers I can think of: Good, readable and heavily commented code, which does not only explain in the comments what the code is doing, but also why.


I'm not convinced that rules like "no answers consisting only/largely of code blocks" are going to be helpful. Some code blocks are clear and self-explanatory and some are not. This is what we have voting for, so vote up the good answers and vote down the bad answers.

I often find myself explaining that the whole approach of the code in the question is wrong, and that the code would be simpler, clearer, more general, or faster, if it were implemented using a completely different approach. And the best way to demonstrate this is to show how I think the code should look, which often leads to the posting of a big block of code.

Some examples:

  1. In this answer I wanted to show how a different choice of language could make an enormous difference to the readability of the code.
  2. In this answer the OP was trying to write a parser without a lexer or any notion of source tokens, so I wanted to demonstrate how the conventional approach to structuring a parser produces better code.
  3. In this answer there were so many improvements to be made that in the end I gave up explaining them and just posted the revised code for the OP to reverse engineer.
  • 4
    \$\begingroup\$ I should make it clear that I'm referring to answers that only contain one or more code blocks. No explanations, not even comments within the block(s). For example, compare this person's answer to mine. The other person's lacks any explanation, whereas mine contains relevant comments throughout. \$\endgroup\$
    – Jamal
    Sep 30, 2013 at 17:41
  • \$\begingroup\$ @Jamal: I think Nikola Vukovic's answer is actually quite good as it stands, and doesn't need any additional explanation. As the comment says, "Simple. Smart. Sweet." So I've upvoted it! \$\endgroup\$ Sep 30, 2013 at 19:30
  • \$\begingroup\$ Then in that case, it's up to those reading the answers to decide. I'm just comparing these two based on explanation / no explanation, regardless of the code. \$\endgroup\$
    – Jamal
    Sep 30, 2013 at 19:33
  • \$\begingroup\$ All of your examples are excellent answers, they're not relevant to this question. Having big code blocks explaining why this, completely different approach, is better is not the problem. Having a big code block without any explanations is. \$\endgroup\$
    – Bobby
    Oct 1, 2013 at 8:36
  • \$\begingroup\$ @Bobby: I'm arguing that if there's a different between my answers and the ones under discussion here, it's a difference of degree, not kind, and we should be able to deal with it by voting, not by imposition of rules. \$\endgroup\$ Oct 1, 2013 at 9:27
  • 2
    \$\begingroup\$ "...it's a difference of degree, not kind..." I disagree. There's a big gap between code-only-dumps and a short introduction before a big code block, as there is a big gap between these and your answers. But maybe we just fell for a simple misunderstanding? I always assumed that "allow these or not" always only referred to how to treat these answers. So if we come to consensus to not allow them, they'd be downvoted on sight and comments would be left that we don't want these kind of answers and that expanding it would be nice. \$\endgroup\$
    – Bobby
    Oct 1, 2013 at 11:47
  • 2
    \$\begingroup\$ @Bobby: I think "use your judgment and vote up or down accordingly" is a better approach than "downvote on sight". If you are really convinced that code-block-only answers are always bad, then downvote them. But I'm not convinced, and I will continue to read them first and then decide which way to vote. \$\endgroup\$ Oct 1, 2013 at 17:21
  • 2
    \$\begingroup\$ @GarethRees: I agree. Here, we're looking at two sides: discouraged vs banned. Even if such an answer is given, it should still be judged based on its correctness. To put it another way: such answers should not be grounds for flagging as Very Low Quality (if some even go that far). The voting is still up to the individual, and I do not expect this question to shift that. It is more of an agreed-upon basis for looking at answers. \$\endgroup\$
    – Jamal
    Oct 1, 2013 at 18:33

You must log in to answer this question.

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