4

The following is a question I asked on SO: Boolean short-circuit not short-circuiting.

When I posted I omitted to specify one of the frameworks that are in use in the code. It turns out that the problem I posted about has a well understood solution for one specific framework.

However, I was not using that framework in that question and a discussion ensued. Ultimately, my problem was a routine oversight, which was pointed out in the selected Answer.

The question was down-voted (twice, at the time of this writing). In the discussion, it was mentioned that a question must provide compileable code.

I have two points I'd like to raise:

  • Are OPs expected to post compileable code?
  • Should the poster be penalized for omitting information, that save for the fact that such information would be valuable in an edge-case, he had no idea was relevant to the question?

Update After reading the discussion on this post as well as the discussion on the Question in question I'd like to add a few more words, and flesh out my position.

Thanks to the community input, I positively agree that the way the code that I presented in the original question could be improved. I also agree that my evaluation of what the problem was, was incorrect and mislead some people. By my own standards, I'd say my question was scraping the bottom of acceptable.

That said, this discussion is both illuminating and disappointing. I congratulate everyone here for championing the principle of exacting clear and rigorous questions. I also believe that without standards, SO, and all of SE-dom would lose it's usefulness.

Yet, while I apologize for not having saved everyone involved in answering the original question more time, I don't believe I have to apologize for the way the question was posted, nor for the question itself. For three reasons.

  • Does a question have to lend itself to generalization? Only askers who have been able to reduce their real-life code should post a question?
    • Corollary Not all questions are easy to research, especially when the problem is not clear.
  • Certainly the onus of making a question as clear as possible is on the Asker, but I've personally answered many questions, much less clear than mine, with much less fuss. Isn't it ok, if the question stumps the Asker, for the question to stump potential Answerers? (Even when not all the facts are included, see point 1)
  • Even though one particular critic wrote this about the accepted answer:

    @Seebiscuit The fact that someone was able to blindly guess the problem given both incompletely and invalid information to go on doesn't mean that the question reproduces it's problem. It means someone guessed at the solution despite the fact that it doesn't reproduce the described problem. Those aren't the types of questions we want here on SO; people just blindly guessing based on woefully incomplete information. We want clear questions with clear, objectively correct answers.

I want to argue that the answer provided, was firstly, not a "blind guess" (I should ask Vidas Vasiliauskas, who answered the question, if he thinks his Answer was a blind guess), but it describes the exact reason I posted the question in the first place. Either there was something in c# that was stumping me, or I had an oversight. Vidas Vasiliauskascaught the oversight.

I'm all for raising the bar. But I boo the notion that there are reasonable questions, that reasonable people can put forward reasonable solutions to, that get down-voted. We can make SO pristine, but sacrifice probably its most outstanding quality, and I believe the reason it was formed: its accessibility.

11
  • 4
    "Are OPs expected to post compileable code?" - not always, but pretty much. "Should the poster be penalized for omitting information... he had no idea was relevant to the question?" - actually making a minimal example usually solves that problem. See stackoverflow.com/help/mcve
    – jonrsharpe
    Commented May 4, 2015 at 20:53
  • While compileable code is not required, it can help you get your answer far faster.
    – Kendra
    Commented May 4, 2015 at 20:54
  • @Kendra I agree, but is that omission the grounds for down-voting?
    – seebiscuit
    Commented May 4, 2015 at 20:56
  • 1
    @Seebiscuit Did someone leave a comment claiming this is why they downvoted? How do you know why someone downvoted?
    – nhgrif
    Commented May 4, 2015 at 20:56
  • 1
    People may downvote a question however they see fit, minus voting fraud. There are people who will downvote a question for not having code they can run, or otherwise missing pertinent information. However, we cannot know why anyone downvoted for sure without their input.
    – Kendra
    Commented May 4, 2015 at 20:57
  • 2
    @Seebiscuit Yes, not having a clear question (as a result of missing, or in this case, completely incorrect, information) is absolutely grounds for a downvote.
    – Servy
    Commented May 4, 2015 at 20:58
  • @nhgrif I don't know. That's part of the reason I'm posting here. To find out if my question, in the opinion of those here, is worthy of down-voting. I'm hoping to improve the quality of my questions in the future.
    – seebiscuit
    Commented May 4, 2015 at 20:58
  • @Servy What was the incorrect information?
    – seebiscuit
    Commented May 4, 2015 at 20:58
  • 2
    @Seebiscuit "In the example above, I'm getting a NullReferenceException on desg.ModifiedBy.Id" You are not in fact getting a NRE on that expression. You're getting a NRE on a completely different expression, and that difference completely changes the answer.
    – Servy
    Commented May 4, 2015 at 21:03
  • I could have just as well gotten the NRE on the problem I stated. That's the point, @Servy, I didn't know why I was getting the NRE,
    – seebiscuit
    Commented May 4, 2015 at 21:04
  • @Seebiscuit No, you could not have (in your actual situation), for exactly the reason that you stated in your question. You yourself explained why that expression couldn't have thrown, even though you claim that it did. There are situations that could cause that expression to throw, but they rely on you being in a situation you're not in. The reality of course if that that expression just isn't throwing, because, in your situation, it's impossible for it to do so.
    – Servy
    Commented May 4, 2015 at 21:08

4 Answers 4

10

You provided a problem statement, and then provided code that failed to replicate the problem that you described. When your code fails to replicate the problem you're describing, that is a problem that you need to fix. Either your code isn't what you say it is, it's incomplete, or your problem statement is wrong. (The latter happened to be the case for you.) Whatever it is, it's something you need to fix, and the question needs to be closed (there is a close reason specifically describing this) until you do.

So to answer your question exactly, no, people are not expected to necessarily always post compilable code. They just need to make sure that the code that they post has exactly the problem described. If the described problem is a compiler error, the code should produce that compiler error. If the described problem is a runtime error, the code should produce that runtime error rather than failing to compile. If the problem statement is invalid output, the code should produce the described output, rather than failing to compile or throwing a runtime error.

If it turns out that being informed that your problem statement doesn't match your code helps you solve your problem, in the act of formulating an appropriate question, then so be it. It is often the case that in clarifying what question you're really asking you end up solving the core problem. If you would like to, go ahead and edit the question once you figure out what you're really trying to ask, and if it hasn't been answered already, go ahead and post your solution as an answer.

3
  • Wait you're saying that because I made a wrong conclusion about what could be affecting my code I gave a wrong problem statement? I would say that your thinking is backwards. Especially, in this case. Once I realized that the problem was the solution was trivial. The problem I had was, in part, because I didn't understand what the problem was. And is it incorrect to misunderstand the problem?
    – seebiscuit
    Commented May 4, 2015 at 21:02
  • 3
    @Seebiscuit Misunderstanding the problem sometimes is a sign that the person with the problem is a novice. A lot of times though, it's a sign that the asker didn't put enough effort into understanding the problem before asking on Stack Overflow. The downvote tool tip says: This question does not show any research effort; it is unclear or not useful.
    – nhgrif
    Commented May 4, 2015 at 21:05
  • 1
    @Seebiscuit Your theories about what might have caused your problem being incorrect isn't an issue, the issue is your description of what exactly didn't work on which you based those assumptions. Given that nobody else has the ability to run your code and observe the problem for themselves (as it isn't a complete example) all that anyone else has to go on is your (incorrect) observations of what the problem is. The result is an unanswerable question.
    – Servy
    Commented May 4, 2015 at 21:06
6

Are OPs expected to post compilable code?

OPs aren't necessarily expected to post compilable code. However, they should be posted the smallest example which duplicates the problem. And if it's at all possible to duplicate the problem in a very small example which is compileable, that's excellent.

But of course, sometimes the problem is that your code won't compile and that's what you're here to ask about. That's a perfectly fine question on Stack Overflow--so how could posting compilable code even remotely be a requirement?

Should the poster be penalized for omitting information...he had no idea was relevant to the question?

The short answer to this question is no. The longer answer is yes, because...

The because has to do partially with what I hinted at in answer to your first question. Before you make your way to Stack Overflow, you should have done sufficient research on your problem. You should have condensed your problem down to the smallest example that reproduces the problem.

If you've done this sufficiently, it will be hard to leave out relevant facts about the problem. You should be presenting a very compact piece of code which describes the problem, and a plethora of detail about the context and everything you've tried, and all the things that don't work and why they don't work. And you need to be certain that people who view your question will be able to replicate your problem.

0
2

Yes, a compilable example is important. That's why the Help Center mentions it explicitly. It is instrumental in Rubber Duck Problem Solving.

Be sure to read the link to imagine what might have happened if you spent the 5 or 10 minutes to create such an example. Pretty high odds that you would have found the problem yourself and never needed to ask the question in the first place. And lots of SO users wouldn't be occupied by Where's Waldo problem solving. And SO would not be saddled with another useless Q+A that made Google decide that SO shouldn't be favored anymore. And a lot of experts decide that contributing to SO is getting to be a waste of their time.

Still surprised that your question got downvoted? Hopefully not.

1
  • Thank you Hans, that Help Center link was thought-provoking. I can see how I could improve the code in the question using the three guidelines written on the post.
    – seebiscuit
    Commented May 4, 2015 at 23:25
1

Original answer deleted. It seems there was a confusion between compilable and reproducible code.


Are OPs expected to post compilable code?

By "compilable" if you mean literally mean compilable without any compiler error, then no, not necessarily. It is not always possible as there may be many boiler plate infrastructure code is required, asking for a literally compilable code is asking too much.

If you have a pure function, which doesn't uses any instance fields or global state, and you have a problem with that function, It is as good as compilable. It can be considered as reproducible code. No need to wrap it in a class, adding the Main method etc.

If the question were

Are OPs expected to post all necessary code to reproduce the problem?

Yes when OP claims there is a problem with his code, it is must. Otherwise, we can't even know what problem OP is facing. And thus the question becomes unanswerable. It will become a playground for "guessing game" and never ends which is what we are trying to avoid. This is the reason why we have a close vote titled "Can't reproduce".

I agree it is not always possible to post all the code to reproduce the problem(it may not fit in SO post). In that case I suggest OP to spend some time in creating a minimal reproducible code. This involves removing the unrelated code, breaking down things as much as possible. Discard any irrelevant information. In the end you have very simple code which reproduces the problem.

In most of the cases, you yourself will find the problem in this stage itself.(I've been there many time). While you're trying to break things down, you'll notice where the problem is. If not, we're here.

You must log in to answer this question.

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