3

I have recently been in situations where I have down-voted answers based on a test case where it fails (these cases may be corner cases though). I usually put a comment to why I have down-voted something.

If I see modifications in the answer, I would retract the downvote and upvote if necessary. But sometimes I have received replies saying: "But why? My code works and I am fine with it."

Since I already have a test case where the code fails, I would consider the OP's working code as a corner case.

How can I deal with this situation?

Notes:

  1. I would restrict the term test case to the input - which is perfectly valid in the premises of the question.

  2. the code fails not because it can't be generalized but because it is poorly written, or doesn't follow good practices - hence fails a test case - In general they set a bad example for future readers.

  3. I would like to consider that majority of the questions asked here are specific to a problem.

  4. Please don't interpret this question as Should I down-vote if the answer doesn't is not general enough?

20
  • 19
    leave it and move on. May 20, 2016 at 14:03
  • 52
    Ehm, your policy is to downvote anything that would fail a unit test edge case? I would imagine you could downvote almost any answer on Stack Overflow on that basis. Stack Overflow isn't just about "perfect" code (if there is such a thing); it's also about example code; code that performs some function, but which might not handle every contingency. It's up to the reader to decide if the code is hardened enough for production work. May 20, 2016 at 14:31
  • 5
    @Robert that's not how it works. People copy-paste code off Stack Overflow every second. You can't expect those people to think of every corner case. For example in my answer here, I subtly explain why every other answer given to that question won't work, and I wouldn't call that edge cases. Yet five of those other answers are upvoted as well. Does that mean that the upvoter carefully considered whether the "edge cases" explained in my answer didn't apply to them, or that they were happy they could copy-paste a three-liner without reading?
    – CodeCaster
    May 20, 2016 at 14:44
  • 61
    @CodeCaster: I'm sorry, but I just don't see how I can be responsible for someone copying my code into their system and breaking things. It's up to them to determine the suitability of my code in their scenario. That said, your answer is a good one; I wish more people posted that thoroughly. May 20, 2016 at 14:46
  • 4
    @CodeCaster any copypaste-coder who ends up breaking his system because he cannot understand the code offered to him, or bother with the security implications of the code he is copying, DESERVES to break his system. I'm with you it's not the way it is now. But hell, I don't think it's OUR responsibility to change this.
    – Patrice
    May 20, 2016 at 14:47
  • @RobertHarvey yes, I'd love to see that people actually consider what they are posting to and copying from Stack Overflow, but that is simply not the reality. It's not so much about obscure corner cases as well as posting some code that very strictly answers the OP's question but fails in pretty much every other case, the latter of which is awfully common.
    – CodeCaster
    May 20, 2016 at 14:50
  • 3
    @Patrice it's not about "breaking their system", but providing code that promises to do what the question's title asks (i.e. why Googlers ended up reading the page), but instead only implements the OP's specific requirements. Or in other words, requires a total rewrite while it could have been made more generic and robust.
    – CodeCaster
    May 20, 2016 at 14:56
  • @RobertHarvey : I would imagine you could downvote almost any answer on Stack Overflow on that basis. Well not so ! :) My answers have been down-voted for the same reason and from my personal experience this is a constructive(and often friendly:)) process where an op understands that some obvious mistakes in code could have been avoided.. At the same time I understand that there is no perfect code
    – sjsam
    May 20, 2016 at 14:58
  • @RobertHarvey : Also, I follow report-immediately-as-you-observe policy here so that I usually expect that the op may add a sidenote regarding a case where the solution would fail or an environment to which it is restricted and this often adds value to the answer. So someone hitting the answer through a search engine may not waste thier time implementing a solution that is not meant for a particular case/environment. This definitely adds some value to the answer. :-)
    – sjsam
    May 20, 2016 at 15:10
  • @sjsam: Are you sure you're not overthinking this? There are a number of things that reduce the signal to noise ratio; half-assed answers is just one of them. May 20, 2016 at 15:11
  • @RobertHarvey : Well, I may be :-) and that is why I thought it is important to know the community opinion on this.
    – sjsam
    May 20, 2016 at 16:55
  • What one person calls an edge case, might really be a different scenario/constraints that really should be a different question of "How do I do X, but also so that Y and Z are met?". There might be lots of scenarios that modifying an answer to meet the whims of a passerby would really modify the original behavior such that it doesn't really meet the requirements of the original question.
    – AaronLS
    May 20, 2016 at 17:37
  • 1
    Downvoting an answer which solves the asker's specific question just because you are able to come up with a different version of the problem where it wouldn't work, seems a bit churlish. If you think other users should be warned of a potential problem, just add a comment or post your own answer. (Unless the answer suggests a bad practise which should never be used, or has an unwanted side effect even in the asker's specific case.) May 20, 2016 at 18:10
  • @m69 : What you mean by different version of problem? The test cases may be perfectly valid in the premises of the question.
    – sjsam
    May 20, 2016 at 18:22
  • Maybe I misunderstood. If you find that the answer doesn't completely answer the question, then obviously you're free to downvote. I thought you were talking about the situation where both the asker and anwerer are satisfied with the answer, and the failing test case is only a potential problem for other users with a slightly different question. May 20, 2016 at 18:36

1 Answer 1

28

Remember that the answer is not just for the OP, it is for all the other people that would ask this question as well but find this answer instead. Even if the OP's data set does not include that edge case does not mean someone else won't have it in their data set. If that other person does have that edge case they would be grateful to see your comment as they know they either need to modify the code or find a different solution. This could save them a lot of time.

It is your vote to do with as you will but if you feel the answer isn't up to par that is certainly a reason to down vote. I would politely comment to the OP that even if it works for them it may not work for someone else. I don't see what else you can do as you want to make the community aware that the answer will not work in all cases.

1
  • 1
    I would politely comment to the OP that even if it works.. stuff is a nice example. :-)
    – sjsam
    May 20, 2016 at 14:18

You must log in to answer this question.

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