15

Every so often I come across an answer where the user says that the code the OP posted works just fine, followed by them re-posting the same code, showing that it does indeed work.

I normally don't flag these answers as not an answer (technically it is an answer) or low quality (debatable), but I do tend to downvote them, leaving a comment saying that it isn't an answer in the sense that they've provided no changes or useful new information, and explain that "it works" is better left as a comment. Usually the real issue is that the OP has failed to provide an MCVE.

Am I wrong in doing this?

11
  • 6
    Sometimes the answer is there is no problem. I think this is a case-by-case scenario.
    – Kevin B
    Commented Jul 10, 2015 at 15:11
  • 1
    I think that's more rare than the cases where the OP isn't posting code that actually recreates the problem. And as an aside I'm not referring to typos etc.
    – j08691
    Commented Jul 10, 2015 at 15:13
  • I do think generally though such answers aren't useful, and by that definition warrant a downvote.
    – Kevin B
    Commented Jul 10, 2015 at 15:14
  • Here's an example of such an answer that was well receied, because it contained more than a simple "your code works fine" stackoverflow.com/questions/31282104
    – Kevin B
    Commented Jul 10, 2015 at 15:19
  • True, although that answer does actually provide some insight and suggestions. What made me ask my question was an answer where there was truly no help or insight of any kind provided. Essentially, "it works" and a dump of the same code.
    – j08691
    Commented Jul 10, 2015 at 15:22
  • 2
    I'm on the fence about it now.. The problem is really with the question, not the answer, why should the answer be downvoted? (I almost said answerer, which might be part of my problem.) If the answer isn't useful, there's nothing wrong with downvoting it.
    – Kevin B
    Commented Jul 10, 2015 at 15:24
  • 4
    @KevinB Such answers aren't really answers. Posting an answer to say that there's a problem with the question (in this case, their provided example doesn't replicate their problem) should be posted as a comment.
    – Servy
    Commented Jul 10, 2015 at 15:25
  • my opinion: "works for me" is not an answer. It certainly might be a useful comment, as it does convey useful information. It does not solve OP's problem. I usually will build a "works for me" test case and put it on pastebin or what have you and link to it in a comment. As @Servy has already said "works for me" may usefully indicate that there is a problem with the question (not enough information to repro the observation). Commented Jul 11, 2015 at 5:58
  • Related: Are “works for me” answers valid?
    – Pshemo
    Commented Jul 11, 2015 at 13:02
  • Such information IS useful. Just the info that the code can work in a different environment is valuable debug info and should not be lost/ignored by anyone. The contributor should then make a choice; either a short answer in a comment, (works for me), which is valuable, or an extended answer with possible solutions and some way of futhering the joint goals of finding a comnplete answer to the problem, and adding to the repository of knowledge that is SO. There is a huge void of debugging skills evident in many SO questions, and anything that spreads those skills IS a good contribution. Commented Jul 11, 2015 at 13:05
  • Related meta.stackoverflow.com/questions/272546/…
    – worldofjr
    Commented Jul 12, 2015 at 23:23

3 Answers 3

32

If the issue is that the OP does have a problem, but the example that they've provided doesn't replicate the problem that they have, then the question should be closed. There's a close reason to specifically state that the question's code doesn't reproduce the problem described.

Posting an answer to say that there is a problem with the question is a non-answer, and should be treated accordingly.

5
  • 3
    Can you elaborate on "treated accordingly"?
    – j08691
    Commented Jul 10, 2015 at 15:31
  • 8
    @j08691 What do you anytime you see an answer that's not an answer? Flag, downvote, and optionally comment.
    – Servy
    Commented Jul 10, 2015 at 15:34
  • It's an utter basic of working with computers, that, a problem, a bug, may come and go. Annoyingly, sometimes code will exhibit the bug, sometimes not, depending on an incredibly diverse set of circumstances. The concept "close questions where code does not reproduce bug!" is amazingly naive.
    – Fattie
    Commented Jul 11, 2015 at 6:13
  • 2
    @Joe: actually, while intermittent bugs due occur, they are (thankfully) in the minority of bugs. In any case, one requirement for a good Stack Overflow question is to provide a code example that reliably reproduces the bug. Yes, there are classes of bug for which this is difficult or sometimes even impossible to do. Oh well...it's still a valid close reason if such an example isn't provided. (I will note that even for classes of intermittent bugs, it is often possible to create a deterministic repro example, by introducing diagnostic code that forces the bug to occur). Commented Jul 11, 2015 at 7:02
  • @PeterDuniho The funny thing is by the time you're at that point you probably already know what to do or at least what not to do, but asking could always give you interesting information.
    – John
    Commented Apr 16, 2017 at 9:09
0

The only time I ever do this, and I think the only time it should be okay, is when posting "the code works" is accompanied by a suggestion of what might be an indication for why it doesn't work on the OP's part. Oftentimes you could close those as well for the reason Servy notes, but I consider it charitable to give it a shot if there's a fairly obvious possibility.

Something like:

(code) This works when I test it on my machine. In the past, I've found when you run into this error it means your session is corrupted, and you need to re-boot the server. Once you do that it should work.

2
  • 2
    I wouldn't downvote such an answer, but i'd be somewhat against upvoting it too. The correct action would have been closing the question. though... I've had a VERY hard time getting such questions closed lately..
    – Kevin B
    Commented Jul 10, 2015 at 15:57
  • I feel like there are some times when we can make a reasonable guess at an answer (based one experience) even without proper information - and honestly, sometimes there's nothing more they could have given you. Corrupted sessions and similar kinds of things are very hard to usefully identify.
    – Joe
    Commented Jul 10, 2015 at 16:04
-2

The design of SE includes a very unfortunate coupling between whether a post is a comment or an answer, and what formatting is available.

Suppose I've written a complete program including the problem code, and it works in my environment. Finding out whether it works in other environments, especially the OP's, would be a useful step towards answering the question. It should be a comment, but the comment limitations prevent posting the complete program.

Personally, I refuse to let SE's poor design or the risk of downvotes get in the way of making progress on a question, so I would post it as an answer rather than not posting it at all.

The best solution to this problem would be for SE to add a type of post that is logically a comment but that allows the same length and formatting as a question or an answer.

You must log in to answer this question.

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