What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 127 Stack Exchange communities.

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?

share|improve this question
    
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). –  Wesley Murch Oct 4 '11 at 15:16
3  
See also: Is “Don't do it” a valid answer? –  Chris Frederick Oct 4 '11 at 15:33
add comment

4 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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 Oct 4 '11 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. –  Wesley Murch Oct 4 '11 at 15:10
add comment

If it's a comment, post a comment.

share|improve this answer
    
Yes, but, to use the OP's example, is the "parametrized query" answer a comment? I think yes, others might not. –  agf Oct 4 '11 at 14:54
2  
This is not always possible. For instance, a large block of code or image. –  Wesley Murch Oct 4 '11 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. –  Kirk Broadhurst Oct 4 '11 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 Oct 4 '11 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 Oct 4 '11 at 15:01
    
I'm not sure either way, which is why I posted it here. –  Kirk Broadhurst Oct 4 '11 at 15:05
add comment

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.

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

You must log in to answer this question.

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