A question is asked by a newbie that contains some code that is a long way from 'best practice' code; it'll probably work but is inefficient, maybe buggy, or isn't going to work as well as it could.

I often see these after they've been answered, and they are usually the simple questions which get very quick answers.

Is it appropriate to give an 'answer' which completely ignores the question but comments on the poster's code? See this answer How to know if a record was deleted using c# for an example.

I tend to think that if done in the correct tone then there's nothing inherently wrong (it's helpful, which is what the site is all about), but at the same the FAQ indicates that you should always give a real answer.

Read the question carefully. What, specifically, is the question asking for? Make sure your answer provides that – or a viable alternative.

There are scores of these type of helpful non-answers given every day (I'm sure I've given quite a few myself). Should they be welcomed, tolerated, voted down, or removed?

  • In your example, imagine that answer was the only one. It would be quite a disappointment to OP and anyone else with the same problem, especially if they are already using parameterized queries (the non-solution offered).
    – user159834
    Commented Oct 4, 2011 at 15:16
  • 3
    See also: Is “Don't do it” a valid answer? Commented Oct 4, 2011 at 15:33

4 Answers 4


It's very common and helpful to put additional notes in an answer that address non-essential parts of the code, but if your post does not answer the actual question it really doesn't belong.

If you really must post an "aside" piece, make sure it's tacked on to the end of an answer, even if it's a brief one. If you don't understand the actual problem, you probably shouldn't be trying to fix the rest of the code. If you do understand it, there's no reason not to address it primarily.

I may be looking for an answer to the same question, but perhaps my code does not suffer the ailments you address in your commentary, so it would be useless to me.

  • Good point -- that kind of help is often too localized. Even if it's not, a person searching for an answer to the OP's question probably doesn't need the same secondary help.
    – agf
    Commented Oct 4, 2011 at 15:07
  • 1
    ...and unfortunately it often falls on deaf ears. I will admit though, I often learn something useful from some of those "additional" bits, even though it wasn't what I was looking for.
    – user159834
    Commented Oct 4, 2011 at 15:10

It can tend to be a judgement call based on how bad the question is. Answering with a best practice alternative is generally acceptable, but make sure that you explain clearly WHY you're answering that way. Don't just say "you're doing it wrong, do this instead". Make sure the OP, and all other visitors to the site, understand the reasons behind your suggestion.

Best practices are frequently real answers. There are plenty of times that what the OP posts is just wrong and they should be instructed not to do it that way. Like you say, make it helpful and by all means civil. Make sure your real answer is just that, though - an answer. If your answer has no real substance to it then it's more likely better off as a comment.

  • In the example, the 'best practices' answer doesn't provide an alternate method of solving the problem though, it's only tangentially related.
    – agf
    Commented Oct 4, 2011 at 14:55
  • I'm just saying in general.
    – squillman
    Commented Oct 4, 2011 at 15:02

If it's a comment, post a comment.

  • Yes, but, to use the OP's example, is the "parametrized query" answer a comment? I think yes, others might not.
    – agf
    Commented Oct 4, 2011 at 14:54
  • 2
    This is not always possible. For instance, a large block of code or image.
    – user159834
    Commented Oct 4, 2011 at 14:58
  • 5
    How can you explain yourself thoroughly enough and provide a code sample to demonstrate your point in a comment? More than a line of code in a comment is pretty awful. Commented Oct 4, 2011 at 14:58
  • 2
    @agf I also think the "parameterized query" answer is a comment. Time to flag, and see if a ♦ agrees.
    – Matt Ball
    Commented Oct 4, 2011 at 14:59
  • @Kirk I agree that's an issue with the site, but posting it as an answer is simply not the solution.
    – Matt Ball
    Commented Oct 4, 2011 at 15:01
  • I'm not sure either way, which is why I posted it here. Commented Oct 4, 2011 at 15:05

One possibility is to give them the choice.

Post a comment explaining that you think the code is bad, outlining how it could be done better and then tell them about Code Review. Of course, this only applies to bigger changes in the code, which cannot be easily explained in a comment.

You must log in to answer this question.

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