26

I found this answer today:

enter image description here

The code itself is fine, but there's nothing explaining the problem or why the provided code fixes the problem.

I commented on the answer requesting the user to add more details:

Please explain your code, instead of doing all the work for the OP.

The user then proceeded to argue that their comments within the code are sufficient. The comments sort-of describe the code, but it'd be useful if there was some sort of description (even one sentence) describing the code, such as the author of another answer on the same question did:

Use a nested loop structure. Use the outer loop to 'walk' down your triangle.

These kind of answers don't educate anyone, and may be hard to interpret for new programmers. Sure, I can interpret the code fine and can tell exactly what's going on inside it, but that doesn't mean a new programmer would be able to.

I read Is it wrong to ask for a description of how/why the code works in code-only answers?, in particular Makoto's answer:

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.

Are code-only answers with comments acceptable? Was I incorrect to downvote the answer + request the OP to expand the answer?

16
  • 27
    " may be hard to interpret for new programmers" you make a good point, but do remember that Stack Overflow is intended for Professional and Enthusiast programmers. That certainly doesn't exclude new programmers, but I think it does presume that an asker should be willing to (enthusiastically) spend some time developing good code reading skills. For relatively straightforward code, that shouldn't be a problem. Commented Nov 14, 2015 at 23:03
  • The only thing I would suggest you do different is possibly take a screen cap of the answer and not the votes. Poster might take offense knowing you downvoted if they find this post. Again, you did nothing wrong. Would stop and unnecessary conversation.
    – Matt
    Commented Nov 15, 2015 at 5:22
  • I don't necessarily agree with what you did, but I will fiercely defend your right to do it. If someone disagrees with you they can always upvote the same answer. It's a crowd-sourcing site; you are part of the crowd. There's no right or wrong in this story.
    – matt
    Commented Nov 15, 2015 at 17:55
  • 2
    There has the answer gone? Is it deleted now? If so, my congratulations, @bob: you have succesfully discouraged the answerer and those who disagree with your point of view (me, at least) can't upvote the same answer
    – ASh
    Commented Nov 16, 2015 at 8:44
  • 1
    @ASh: The loss of that one answer is not that big, considering there are several equally good answers which do add various snippets of extra information; and it seems this particular answerer may have learned a valuable lesson.
    – Jongware
    Commented Nov 16, 2015 at 10:34
  • The answer to the question in your title is yes. I don't see a reason to write some prose if code (without or with comments) answers the question and is self-explaining.
    – Roland
    Commented Nov 16, 2015 at 13:07
  • 1
    @Roland The problem was that the comments didn't sufficiently explain the code.
    – AStopher
    Commented Nov 16, 2015 at 13:59
  • 6
    @matt: Upvoting because one disagrees with a downvote? Votes aren't for voting on how others voted, but for voting on the post. Doing otherwise just devalues all votes. Commented Nov 16, 2015 at 14:10
  • @bob I'm aware of that. However, your question title generalizes.
    – Roland
    Commented Nov 16, 2015 at 15:14
  • Depends on exactly what you mean by "acceptable". It may be acceptable in that it is an answer to the question and isn't sufficiently low quality to be deleted. If the comments aren't thorough enough to explain what's going on, you can of course downvote it.
    – Kevin B
    Commented Nov 16, 2015 at 15:44
  • @Deduplicator By "disagrees" I mean voting because one thinks the answer is good as opposed to bad. Some will say one thing, others will say another. Hence it cannot be "wrong" to think it is bad; Stack Overflow is about different people having different opinions. The wisdom of the crowd will determine the score.
    – matt
    Commented Nov 16, 2015 at 16:59
  • 1
    @matt Well, I have no quibble with that. Trouble is when people upvote because "it doesn't deserve the downvote", or the other way around. Commented Nov 16, 2015 at 17:25
  • @Deduplicator I sort of disagree. Why is that "trouble"? What meaning does it even have? There's a Heisenberg Uncertainty Principle at play here. You can't know where the wisdom of the crowd comes from. You don't get magical insight as to why anyone does anything. It could be they had a bad breakfast! The point is that in general it doesn't matter: it all comes out in the wash. The crowd as a whole awards the score. That is crucial to Stack Overflow. Thus, the OP's action is neither right nor wrong: it's just part of the game.
    – matt
    Commented Nov 16, 2015 at 17:30
  • 2
    @matt: If votes are used for anything but saying "This post is useful" respectively "This post is not useful", all votes values are diminished because they mean different things. If you aggregate apples and bananas, you'll only get fruit salad! Yes, one must account for there being a certain percentage of bozo's, trolls, and people who should first work out their frustrations, but you shouldn't encourage anyone to be part of the problem. Commented Nov 16, 2015 at 17:33
  • @matt Create a Meta post on that, and see what everyone else thinks. Will probably get to -20 very quickly.
    – AStopher
    Commented Nov 16, 2015 at 18:58

5 Answers 5

18

I think your actions were just fine.

What you did do that was good:

  1. Comment - requesting more detail is perfectly acceptable here. People should explain why their solution works. The comments here are kind of useless. They don't provide any more information than reading the code would. Useful code comments should help provide context and explain the algorithms used, which isn't done here

  2. Downvote - I downvote unexplained code "answers" as well, though I usually request more details first, then downvote if nothing has been added after a couple of days.

What you didn't do that was also good:

  1. You didn't flag - thank you for not flagging as NAA or anything else. This is not a great answer, but it does qualify as an answer nonetheless.

I think these kinds of answers help people with their immediate issues, but they don't do much to aid in future understanding. We should be striving to encourage growth in the developer community, so that people can start solving their own problems, then eventually help contribute solutions to others' as well.

I believe your actions were helpful and correct in supporting this goal.

0
36

Good comments don't repeat the code or explain it. They clarify its intent. Comments should explain, at a higher level of abstraction than the code, what you're trying to do

I think this sentence alone (blatantly copied from Wikipedia, whose source is from Code Complete by Steve McConnell) proves that the comments in this specific answer are not good comments. They do not clarify the intent of the answer, at all.

As an example, consider the very first one:

// start with 'A' - 1 character
char chNew = 'A' - 1
  • An individual that knows how to read that code find the comment useless because it tells exactly what's written.
  • An inividual that does not know how to read that code finds it also useless because there is no indication as to why this line of code is here.

Thus, this specific answer comes down a code-only answer and should be treated as such. Which is exactly what you did: downvote and comment the answer, inviting the answerer to expand, so I think your actions were correct and appropriate.

As to the more general question of handling code-only answer with comments, what I would do is the following: Are the comments good?

  • Yes: do nothing / upvote
  • No: downvote and comment
3
  • abstrusegoose.com/432 Commented Nov 16, 2015 at 12:24
  • 6
    I think you make an important distinction based on what's in the comments. If the comments explained what was wrong with the OPs code, at lines where the answer's code was different, that can work. I've sometimes posted answers that were mostly commented code. Usually with at least a one-sentence summary though. But anyway, if you put the English-language part of a good answer in a comment instead of a separate paragraph, it can still be a good answer. Commented Nov 16, 2015 at 12:34
  • 2
    "Are the comments good?" Exactly. Now, comments in code in an answer have a different purpose than comments in normal code, because arguably with a novice you might well say in English what the code is saying in C (in this case), whereas of course Steve McConnell is quite correct that much of the time, that's just silly in real code comments. But these comments didn't even really do that. :-) Commented Nov 16, 2015 at 15:45
5

Are code-only answers with comments acceptable?

It depends. A code-only answer with comments can be a good answer, if the comments are good. After all, they're just explanatory text inside the code block, which can be as useful (or not useful) as explanatory text outside the code block. We can't judge purely from whether the explanatory text is marked up as a comment in a code block or not.

Was I incorrect to downvote the answer + request the OP to expand the answer?

I think you were correct. Context is important. Answering that question requires telling the OP what's wrong with their approach and why another approach would be better. You could do that in a comment, and if you did it could be a good answer, but it makes more sense as prefatory text outside the code. Then, comments in the code highlighting what's going on (probably in a way we wouldn't in "real" code) would accentuate and support that preface.

4

Personally speaking, I think you did fine.

You are of course free to use your votes however you want, but the main point is that you did attempt to address your concerns with the answer. They simply chose to ignore your concerns, which is unfortunate; the answer could be good, but just giving someone code to copy and paste into whatever they're doing isn't the best approach.

3

From my point of view, this code-only answer is(was) good.

there's nothing explaining the problem

Comments in the code actually describes algorithm, and ...

but there's nothing explaining ... why the provided code fixes the problem

... exactly algorithm was a problem for the asker. The asker knows (according to question post) that letter character is actually a number, which can be compared and be used in arithmetic operations such as addition.

Code in the answer uses nothing above asker's knowledge. Nested loops are just new things, but such things can be well expressed by the code itself.

That's why your comment

Please explain your code

here seems itself broad: What exactly is not cleared from the answer?

It could be (just example):

Could you describe algorithm you use in the code? It could be useful for other readers.

In any case, as noted by others, your downvote+comment correctly express your point of view.

8
  • I've already explained why this particular answer isn't great, please read the whole question & its other answers.
    – AStopher
    Commented Nov 16, 2015 at 10:54
  • BTW, when you post comment, describing downvoting reason, no reason to delete this comment immediately when revert downvoting. Especially when topic in that comment isn't yet cleared by the opponent:) (This all is about my answer post).
    – Tsyvarev
    Commented Nov 16, 2015 at 11:15
  • I've been here longer than you, and have more experience, rep does not matter here. cleaned by opponent- you really don't get what Meta is for, do you?
    – AStopher
    Commented Nov 16, 2015 at 11:16
  • I bother about deleting comment, I aware that rep isn't affected on Meta. And I really failed to understand(failed to clear it), what you want to say with deleted comment(lucky it was short and I remember it) and with the next one. As I currently see your question post, you describe particular code-only answer, point to problems, which you see in it, and actions, which you have done. And ask others, whether you were right in your actions. In my answer I point, that problems you reveal was subjective, and I don't agree with them. So this changes a light of your actions.
    – Tsyvarev
    Commented Nov 16, 2015 at 11:33
  • Your point being?
    – AStopher
    Commented Nov 16, 2015 at 11:41
  • Sorry, but I don't undestand that question. What you mean by your point being?. My point of view on that question? [And what happens with comments to current post? I definitely haven't deleted my first comment, but isn't shown. Probably, I miss a way how Meta process comments.]
    – Tsyvarev
    Commented Nov 16, 2015 at 12:11
  • I flagged it as obsolete, because it was.
    – AStopher
    Commented Nov 16, 2015 at 12:37
  • 3
    Oh, OK. But it is definitely a strange way to discuss with comments being removed so quickly.
    – Tsyvarev
    Commented Nov 16, 2015 at 12:40

You must log in to answer this question.

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