Sometimes I see someone post a question that amounts to "I have a function that doesn't work; what's wrong with it?" They post the code to the function; usually it's an MCVE. The problem is that it's often just... wrong. It's not that there's one mistake; it's that it's a completely incorrect algorithm, or there are so many issues with the code that the right answer is very nearly "start over and try again".

My reaction to this is usually a close vote as "Too Broad", given the breadth of issues usually in play, as well as a comment essentially saying that there are a lot of issues. However, I often see people answer these questions by simply posting a complete rewrite of the function which behaves correctly. What is the right answer in this case? Is posting a fresh chunk of code considered a good answer, or should the question be closed?

For context, this is the question that made me think of this.


Disclaimer: Mine is currently the top voted answer to the specified question.

I'll be honest with you: I didn't read the snippet in the question. I read the title, and the example input and output. I then glanced at the provided code, saw that they were on the wrong track and wrote a "correct" solution.

Especially for simple, non-specialist problems like this, I think that providing top-quality answers is more important than patching structurally flawed code so that it works. Those users that just copy-paste answers into their own code aren't going to care, and those who come to learn something will either do so directly from the answer, or ask for detail in comments, or be inspired to google something

Regardless, we can't ask people to adhere to some arbitrary standard of knowledge when asking questions. Instead, all we can ask is that people follow the rules of this site when asking questions.

I would rather 100 people with no knowledge of programming ask simple questions including their best attempts, than a single knowledgeable person asks an interesting question without trying anything on their own.

  • 1
    "I would rather 100 people with no knowledge of programming ask simple questions including their best attempts, than a single knowledgeable person asks an interesting question without trying anything on their own." Effort has no inherent value in a question; it's only about making the problem clear and explainable. (Also.) This also doesn't seem to square with your "arbitrary standard of knowledge". Why have an arbitrary standard of labor then, when that's even less useful? – jscs Jan 9 '18 at 12:28
  • This is how it ahould be done (other than the irrelevant arbitrary labour requirement brought up by josh) – user4639281 Jan 9 '18 at 15:35
  • My thinking was more that the question asker was making some good faith effort to interact with the site according to our rules. The how to ask page encourages people to share their attempt at a solution, even if that attempt is poor. The site rules have a (very low) standard of labor (try something, anything on your own). They do also include a standard of knowledge (research the problem before bringing it here), but that's more difficult to prove in a Q&A question. – Patrick Haugh Jan 9 '18 at 15:55

If, as you say, the question contains a "minimal, complete and verifiable example", I don't think the question should be closed just because the code contains several errors. The questioner has done what we asked (provided an MCVE), and presumable had no way of knowing how many different errors were in the code.

On the other hand, if the question shows no research (which might be the case in such questions), it is certainly reasonable to down-vote.

I see that the question you linked to has actually been closed for having no MCVE, so it may not be a good example of what you describe in your question.

  • 2
    If you don't close it ASAP, someone will answer in the way described by the OP. Next Sunday, before 'homework submission Monday', 10 users will copy some crap from the net, plag another student or just plain make stuff up that likely does not even compile. Week, later, it's 100.. – Martin James Jan 9 '18 at 3:00
  • @MartinJames Can you explain what you mean? The question is about whether an MCVE that happens to contain more than one error is too broad. I don't see how your comment applies to that. – Blackwood Jan 9 '18 at 3:04
  • 1
    @Blackwood so.... you should always tone down the MCVE to be about the specific issue you are trying to fix, correct? And that issue should be more specific than 'my code doesn't run'. The way i see it, if your issue is "I am trying to foo the bar', your MCVE shouldn't also have NPEs (unless they relate to fooing the bar)... if it doesn't, then it isn't minimal to show your 'fooing the bar' issue – Patrice Jan 9 '18 at 5:20
  • @Patrice I'm sorry, I don't understand your comment. – Blackwood Jan 9 '18 at 5:25
  • 2
    No worries. I may have been clearer in my mind. My point is, your post should be about a specific programming problem. In isolating your specific problem, you should be able to make your mcve minimal enough that the other problems in your code won't be part of it. Extreme example: if your sql queery doesn't give results as expected, ask about that. Don't post the code containing both the query and the connection to the database. They should be two separate questions, if both have an issue (any clearer?) – Patrice Jan 9 '18 at 6:20

You must log in to answer this question.

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