3

In general; if you see someone post a question which includes code, and you know there's a better/safer way to perform the same function, should you address their coding deficiency or just stick to answering the question they've posed? I'm just thinking in terms of what SE stands for; a repository of coding questions and answers and NOT for specific questions geared towards one individual. Addressing issues outside the question won't help future visitors as they'd never be looking in a question about, say, connection strings if their question relates to If/Then/Else loops. The flip-side is, if it only takes you a minute to point out a better way to do something, then that person has learned more and will be more likely to return/stick around and join the community.

Just curious what the masses feel about this topic.

| improve this question | | | | |
9

First, answer the question, directly and fully.

If, after that, you have the time and energy to also critique the OP's code, go for it. For bonus points, encourage the OP (in a comment) to post their working code at Code Review Stack Exchange for a more thorough critique.

| improve this answer | | | | |
5

I think it would be better to answer the question first, and then point to the improvements. As an example, I have seen many questions related to SQL queries with C#. Most of the time the problem is usage of incorrect method or syntax. But almost all of those questions have used string concatenation to build queries. I would ask them to parametrized their queries since it I will save them from SQL Injection.

I have seen answers getting downvoted because the answer failed to point SQL Injection vulnerability in the question.

So IMO, helping out the OP along with better coding technique would help the OP as well as future visitors.

| improve this answer | | | | |

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