64

Checking the low quality queue on Stack Overflow, some code-only answers came up. I visited the questions in particular (I normally do that before deciding if I should skip or take action) and found that, although the answers didn't really fix the problem, they (or at least some of them) could be used as a guide on how to fix it.

After reading different posts on Meta (one, two, three, four, five), I decided to leave a comment to the users, stating that an explanation of how/why that code worked would be ideal. But my comments were met with "the code speaks for itself" or "everyone knows this." In one particular case, I downvoted the answer, and when I tried to explain why I considered the code didn't speak for itself, I was told (by the user) that I was harassing and making him/her feel unwelcome to the site.

I am new to reviewing and don't want to do things wrong (and even less being rude/offensive to other users). Is it incorrect to add comments asking for an explanation of how/why the code works in code-only answers?

If I know how/why the code works and think that it could be improved by explaining it, should I directly edit the answer and add the explanation myself? Or should I write a comment and leave it for the user to do it? (After all, they are the authors.)

As mentioned, the few people, to whom I left such a comment, didn't agree with it and/or criticized me for writing it. So one last question related to how to proceed in cases in which the author considers the code is enough and doesn't modify the answer: If I think that the code-only answer is not enough or that it doesn't fully answer the question, and the user replied negatively to update its content, should I consider it unsalvageable and flag it as very low quality?

12
  • 26
    Personally, in those situations, I tend to leave a comment (as you did), down-vote and, if possible, vote to delete. Code-only answers are too localised, and offer nothing to future users to educate them as to the problem. Commented Apr 14, 2015 at 19:22
  • 1
    I saw one of the posts you are referring to and I think you handled it correctly. You provided constructive feedback and the person answering went kind of off hinge. There wasn't anything negative on your part and his answer could do with a brief explanation of why that selector worked better. Commented Apr 14, 2015 at 19:26
  • One of my personal gripes. See meta.stackoverflow.com/questions/277738/…
    – Jongware
    Commented Apr 14, 2015 at 19:40
  • 12
    @HansPassant "They click the Ask Question button." the OP is asking about code-only answers. So, someone has already done as you said, gotten an answer, and wants the answerer to provide an explanation of the code so it will be a better answer and help more people. Perfectly reasonable
    – codeMagic
    Commented Apr 14, 2015 at 19:42
  • 1
    The OP wants to ask a question about code he doesn't understand. That happens, we don't expect SO users to post code that everybody needs to understand. Answers are normally targeted to the OP and the tags he selects, I for example personally don't expect for somebody that posts a Haskell answer to explain it to me. If he's curious and wants to learn more than clicking the Ask Question is perfectly reasonable. Commented Apr 14, 2015 at 19:49
  • 18
    @HansPassant No. "If I know how/why the code works, and think that it could be improved by explaining it" he is in the queue, sees questions that could be improved by an explanation, so he wants to know if he is correct in asking that the answerer fixes up the answer. Also, "Answers are normally targeted to the OP" that's not how the site is supposed to work and so this caring citizen is trying to help fix that.
    – codeMagic
    Commented Apr 14, 2015 at 19:55
  • 1
    No. Reviews are normally done by SO users that are not up to speed on the specific [tag] subject and they tend to look for secondary issues with the post. They press the Red Button when it is a code-only or link-only answer for example. If the author of the post already indicated that expanding the post is not necessary then the buck stops there, you can't force him. He can DV the post if he doesn't like it, that however doesn't make him any wiser about the post content. Commented Apr 14, 2015 at 20:16
  • 2
    If we know how to explain it, are we allowed to edit the explanation in?
    – jkd
    Commented Apr 15, 2015 at 1:33
  • 3
    I will often add "This answer would be improved by explanation of the code". Code-only answers only work for the most trivial of cases, and anything else would benefit from even just a little detail .
    – Sobrique
    Commented Apr 15, 2015 at 9:53
  • 1
    @jakekimds it is fine to do as long as you aren't changing the meaning of the answer and you know the author's exact intentions of the answer. But I think it's best to let the author have a crack at it by suggesting so in a comment. I did one just yesterday because it was just a short and simple explanation.
    – codeMagic
    Commented Apr 15, 2015 at 12:48
  • 2
    Statements like "everybody knows this" seem to assume they know everyone the world, I think you did right. The code could be great and really solve the problem and some other user could still not understand it because it requires some underlying knowledge he doesn't have. And as Hans suggested he could ask another question, but is just a waste of time, when the original user could have added the explanation. Sometimes you don´t even know what to ask, and users may wind up creating questions repeating all the content of the original one just to understand the solution.
    – Dzyann
    Commented Apr 15, 2015 at 14:08
  • Related: meta.stackoverflow.com/q/256359/1947286
    – apaul
    Commented Apr 15, 2015 at 15:46

1 Answer 1

70

There is nothing wrong with this at all. In fact, any answer that is exclusively code-only should be downvoted, as it's not entirely useful.

While we can read and understand code, the better teaching tool (in my opinion) is to explain the rationale behind the code. If a person is unwilling to do so, then you could either leave a comment, downvote, or both. If they add an explanation, that's great - if they don't, then this leaves an opportunity for someone else to come along with a more complete answer.

Ultimately it's up to the answerer if they elect to update the answer, but if they don't, then you can downvote it.

Flagging it as "very low quality" is appropriate in select cases, as pointed out by Flexo: if the code is a genuine attempt at an answer, then a flag wouldn't be an appropriate action to take.

10
  • How about this part of the question? "should I consider it unsalvageable and flag it"
    – ryanyuyu
    Commented Apr 14, 2015 at 19:23
  • @ryanyuyu: I've addressed it now.
    – Makoto
    Commented Apr 14, 2015 at 19:24
  • 28
    Assuming the code isn't just gibberish I'm likely to decline VLQ flags on code-only answers that look like genuine attempts at answering for the simple reason that deleting them leaves things worse off than when I found them. The only action I would take is a downvote/comment and that's something that doesn't need mod powers. Commented Apr 14, 2015 at 19:51
  • 2
    You raise an interesting point @Flexo. If the question would be better with this code-only answer, then such an action makes sense...how often do you think you've encountered that case?
    – Makoto
    Commented Apr 14, 2015 at 19:53
  • 2
    It's a difficult call to make without being a domain expert so I tend to play it safe. I think it happens fairly frequently that they're useful, hence my reluctance to delete in all but the most awful cases. (Just identical to existing much older answer or just plain nonsense). The problem is that defining exactly what a code-only answer needs to do to be useful is tricky because the missing item is exactly the cue I normally use to judge an answer I'm not an expert on. If it potentially makes sense to someone else in the future and flips a proverbial light on for them it's worth keeping. Commented Apr 14, 2015 at 20:47
  • 3
    These are exactly the cases where you want community experts, not moderators to be dealing with them though because they are the subject experts that can make a reliable call. Commented Apr 14, 2015 at 20:48
  • 6
    "any answer that is exclusively code-only should be downvoted" Generalizing a bit, are we? Sometimes the code is self-explanatory enough to stand on its own. Here I'm not even talking about code that contains explanatory comments. Commented Apr 15, 2015 at 9:18
  • 5
    @Jean-FrançoisCorbett: Code that is self-explanatory is both a subjective concept and rare to those of us who are indoctrinated. It's subjective because of our skill level; we can't say for sure that someone would just "get" a block of code that's self-explanatory if they're a beginner. It's also very rare in the sense that, while I've understood a lot of snippets of code intuitively, having the explanation as to what it's supposed to do at a higher level has greatly aided my understanding.
    – Makoto
    Commented Apr 15, 2015 at 21:22
  • 1
    Thanks for the perspective on it @Flexo; I've revised my remarks on the flagging bit with your experience in mind.
    – Makoto
    Commented Apr 19, 2015 at 4:05
  • 1
    "Code that is self-explanatory is... a subjective concept [.]" - Makoto This. Understanding "what it's supposed to do at a higher level" not only explains why the code works, but can inspire original thought towards additional solutions and even highlight the root cause of other seemingly unrelated problems. Give the man a fish AND teach him how to fish.
    – OhBeWise
    Commented Aug 6, 2015 at 16:21

You must log in to answer this question.

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