-21

Consider this Stack Overflow question:

Uncaught TypeError: Cannot read property 'addEventListener' of undefined

There is a simple change - the author uses <= instead of <. So I quoted a small fragment of the code (it's only 17 characters!) and wrote the right fragment.

  1. Why is such an answer bad?

  2. Why was it edited (see revision 2) to leave code from the question without quote?
    And it's not the first edit of such type I see.

18
  • 5
    You should add some explanation, at least like try this code or there is a typo in your code. what does random code block mean?
    – Sandeep
    Jun 3, 2016 at 12:14
  • 1
    @Sandeep, it's a qoute plus fix. How does phrase "try this code" should help? Does everybody always posts the code that should never be tryed so that I need to explicitly specify: "Hey, try this!"?
    – Qwertiy
    Jun 3, 2016 at 12:17
  • 11
    No, but thousands of people post random code garbage every day. That's one reason why we don't want code-only answers. Why is it that hard to add a bit of context and explanation about what your code does? "There was a typo in your code - you used <= instead of <. This should work: ..." is perfectly sufficient.
    – Pekka
    Jun 3, 2016 at 12:19
  • 8
    "Try this" does not really add any value. I'd recommend to explain the difference between the two lines of code in words also.
    – Floern
    Jun 3, 2016 at 12:20
  • 1
    @Qwertiy Just see the answer above your answer in that question.
    – Sandeep
    Jun 3, 2016 at 12:20
  • @Floern, is it so difficult to compare 17 chars without a hint? It's not 17 lines, it's 17 chars!
    – Qwertiy
    Jun 3, 2016 at 12:21
  • @Sandeep, that answer was posted after mine. If it was posted before, I wouldn't post any answer.
    – Qwertiy
    Jun 3, 2016 at 12:22
  • 4
    is it so difficult to compare 17 chars without a hint? It doesn't matter. You need to look beyond your specific situation. This is a huge community that deals with hundreds, if not thousands of such answers every day. We need rules that can deal with all those code-only answers, not just yours.
    – Pekka
    Jun 3, 2016 at 12:22
  • 4
    @Qwertiy no, the difference is pretty clear, but you might explain why this difference fixes the problem.
    – Floern
    Jun 3, 2016 at 12:23
  • @Pekka웃, so what? I think that any minor code change can stay uncommented.
    – Qwertiy
    Jun 3, 2016 at 12:23
  • 7
    Simple answer: comment that they had an off by one error and then close vote is with: This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting Jun 3, 2016 at 12:34
  • 3
    @Qwertiy Why are you arguing with people? You asked for why your answer wasn't well received, honestly, don't ask if you don't want a answer.
    – Epodax
    Jun 3, 2016 at 12:49
  • @Epodax, if these minds are answers, then why they are comments?
    – Qwertiy
    Jun 3, 2016 at 12:55
  • 6
    For some reason, even though it's equally unhelpful, "try this" annoys me so much more than code only. Is that just me? Jun 3, 2016 at 14:32
  • 2
    @BSMP I think that's often true. I usually interpret it as "Here's this; I won't take the time to explain it because that would keep me from posting something as quickly as possible, but people don't like it when you only post code, so 'Try this'. Please accept and upvote my answer. Thanks in advance." Jun 3, 2016 at 18:08

2 Answers 2

6

It seems fairly obvious to me why code-only answers are bad. However, perhaps in your case it's not. This almost perfectly highlights one of the key issues with code-only answers. You may well think it's obvious what your code now does and why it does it, but the OP / other readers may not.

Now let's stretch your example just a little further. Imagine you wrote a similar answer with three or four more lines of code. Now, when the OP scans the code it may not be obvious at all that you made that change. This may result in them coming back and saying it doesn't work, leaving you a bit baffled.

You may well argue that it's only 17 characters! However, you may well change all of those 17. Are you suggesting that there should be some sort of algorithm that picks how many characters you've written, if it's a code-only answer, how many of them correspond to the original code, how many of them have been changed, how likely this change is to be spotted, etc., etc., etc. Hopefully you get my point. Where do you draw the line?

As I say, yours seems to be a fringe case, and to 99% of readers will be seen and understood, but there are plenty out there that are only a little longer than yours where this percentage would start to drop to unsatisfactory levels.

5
  • Yes, agree with you. I've never told that all code-only answers are good, that's only about minor changes. By the way, why everyone ignores the second question about edit? Why such edits happen? It's a second or third time I see edits like this in my answers. The previous one replaced the quote by phrase "try this".
    – Qwertiy
    Jun 3, 2016 at 13:42
  • @Qwertiy - In terms of the quote edit, my guess would be that grammatically it's not correct to show YOUR code as a quote. The first line is a quote, as you're quoting the OP's code. The fix however is your code, so isn't a quote.
    – sr28
    Jun 3, 2016 at 13:46
  • The original answer was code from question as code inside of quote and my fix as code outside of it. In second revision dippas made code from question (without quote) followed by horisontal line followed by code with fix - I see no sence in this edit, moreover I think it makes answer unclear, so I reverted it. By the way, in the 4th revision Peter Cooper Jr. adds phrases "Where you have" and "You actually want" - it's ok, but I don't see any benifits from them in the answer. My code has newer been placed in any qoutes. Only code from the question was.
    – Qwertiy
    Jun 3, 2016 at 13:51
  • @Qwertiy - IMO I don't think the first quote helped. It only works with explanatory text. I don't think code should be written as a quote like that, so I can understand the edit, but then it becomes less clear. However, that sort of edit does work when the final explanatory text is added.
    – sr28
    Jun 3, 2016 at 14:01
  • 2
    "It seems fairly obvious to me why code only answers are bad" - where can we get more of you?
    – CodeCaster
    Jun 3, 2016 at 14:03
4

If the question is truly typo - it should just be closed as such without providing an answer. It is a good idea to provide a comment on how to fix the problem along with VTC.

If the problem is actually caused by a misunderstanding of some sort (even if it is a single-character change) you should either find a duplicate or provide an explanation why the code is behaving wrong.

I.e. in this particular case, the issue was caused by a misunderstanding of how to iterate collection of items or how for loop works - neither of which explained in discussed code-only answer. The answer that demonstrates good practice of answering such question is provided by Justinas in the same question:

Enter image description here

6
  • And that particular issue is a duplicate of a question with an ID lower than 1000, I'm fairly sure. It should simply not be answered.
    – CodeCaster
    Jun 3, 2016 at 14:44
  • Yes, that answer is good. But most peopte are too lazy to wrte such answer for such question, or to search for a duplicate when it's enough to change just one minor thing. You tell, there are better ways then just fix this thing - yes, there are. But if the better thing exists it doen't mean that the current one is bad by default.
    – Qwertiy
    Jun 3, 2016 at 14:48
  • @Qwertiy Totally agree... But code only answers are downvoted not because there are better way to answer in each particular case, but because there is no way to learn from most of them. One really should not expect to get upvotes on post where no efforts are shown - whether it is question or answer. Jun 3, 2016 at 15:13
  • @AlexeiLevenkov 1. most != all 2. "should not expect to get upvotes" - yes, but downvotes too?
    – Qwertiy
    Jun 3, 2016 at 15:15
  • @Qwertiy I did not find your particular code-only answer to be that rare exception and call it not useful - would likely downvote if see it directly (not from META link). The only suggestion I have to change such behavior - educate all, especially new users to providing brilliant and self-explanatory (not trolling) code only answers - some people may change they opinion about such posts afterward. Jun 3, 2016 at 15:28
  • 3
    @Qwertiy downvote on answers is "this answer was not useful". I am a firm believer there are too many copy/paste coders in the world, and that creating more is extremely unhelpful. Personally, that's why I downvote these.
    – Patrice
    Jun 3, 2016 at 15:59

You must log in to answer this question.

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