This is hardly a new issue. My own opinion is that when someone asks, "How do I do X?" Sometimes the best answer truly is, "Don't do X."
In this case, the answer provided is most certainly a valid answer. It might not be one some agree with - they should downvote it - but it 1) indicates that the OP shouldn't do what they are asking to do, 2) indicates why the OP shouldn't do it, and 3) provides alternatives. It is brief, which some don't appreciate, but it is clearly an answer to the question asked and should remain an answer.
Below is a quick summary of the reasons a "don't do it" answer is an acceptable answer, followed by quotes from previous discussions of this issue.
Reasons why Don't Do It is a valid answer
- Voting will generally correctly adjust the visibility of such answers
- The OP still gets to choose the "accepted answer" and thus which one is on top and/or marked as most useful
- It helps the questioner consider their problem more carefully
- It helps highlight questionable practices and gives others the opportunity to not just vote them up, but also vote them down when wrong (comments can't be voted down, so they are not a good place for "Don't do that" answers)
- Helping the person in need is good, but others will come along later with similar questions that aren't exactly the same and having a comprehensive answer section with a lot of answers, including "don't do that", will not only help the OP, but future visitors. Remember, this is a repository for knowledge and expertise, not just a help forum. Many different points of view are welcome and desired, not just for the OP, but for everyone.
- "Not an answer" flags should be used for answers which pose a question for the op (ie, comment), or not in any way related to the question, not for answers the OP might not want to see, or others disagree with - the OP and others have voting and accepting votes that will take care of all other kinds of answers
I feel that ... the answer should stay. Typically, voting will correctly adjust visibility of the answer up/down appropriately. The answerer was attempting to answer the question - they were trying to adjust the point of view to show that perhaps the parent was approaching the issue in the wrong way, which is a perfectly valid outlook even if it doesn't solve the question as asked. Evidence (votes) suggests that such an adjustment of viewpoint is a popular opinion on the topic, even if many voters aren't from our (honestly, fairly small) community of active users.
In the end, if the OP decides a different answer is 'better' (which, for all we know, they may not. Perhaps the given answer is eye-opening and does change the OP's mind of how to approach the situation), then they'll mark a different answer as correct. Once they do so, the marked answer will jump to the top regardless of votes. Future readers will see the selected answer first, but if they choose to continue reading they'll see the alternative viewpoint as is always the case.
All in all, the "Not an answer" flag should be used for "answers" that truly don't even attempt to answer the question - they either are spam, pose a question for the OP (should be a comment), or are completely unrelated to the topic at hand.
I think it's a valid answer, provided that you explain why the OP shouldn't do it (which you did in the question you gave as an example). But I would consider also to answer the actual question, too. As in "Don't do it because of A, B and C. But if you decide to do it anyway, I would follow this approach:..."
I have recieved one or two Don't do it answers on my questions, and I find it very helpful to question my own decisions on how to approach a problem. (It also bruises my ego a tiny bit, but that is outweighted by the benefits).
I think it often is appropriate; I see examples of this all the time. The O.P. may not accept the answer, but other folks very well may vote it up. If it gets voted down, well, then people don't agree with you. But it's worth a try. And someone else who is closer to being on the fence may search, find your answer, and think twice about implementing the questionable practice.
Remember that StackExchange is supposed to be a living repository of questions and good answers. It's actually not all about helping the person who posts the question; it's about helping anybody who ever reads your answer.
In other words, you're wondering if "Don't do it" is a valid answer?
Yes, it can be. Depends on how you approach it. If you explain why it's a bad approach, or how there's a better way, that's perfectly okay.
...what about other people's negative answers? How should we react to them? Well, there are good negative answers and there are bad ones. Bad ones disrespect the asker or the asker's point-of-view, don't justify their answer, or attempt to ram what is an opinion down the asker's throat.
If it's not an answer at all or abusive, then flag it. If the answer is terse and holier-than-thou, then maybe downvote it. If it's negative answer but one that might help the asker, then it's candidate for upvoting. Reinforcement from votes can help the asker come to accept the "bad news" about their current approach. In any case, as long as it is an answer, then judge the answer based on its merits like you would an answer in the positive.
Yes, if it's a good answer in its own right. It needs to include actual expertise or research or facts saying why not to do something, and ideally suggest an alternative.
Sometimes, askers say what they're trying to do and what they're stuck on, then an answerer tells them to try an entirely different approach. I would view a good "don't do this" answer as in this class of answers.
I'll also note that sometimes these answers can be blunt and snarky. I don't think that's constructive - the OP didn't really learn anything besides the fact that at least one person on the internet thinks she didn't do that, which she probably knew before posting a question. These should be constructively downvoted, with a comment explaining that this could be a good answer if it were educational instead of curt.
Should we not give questioners the benefit of the doubt
NO! At least, not always. ...I at least am not going to let an obvious ... issue go unchallenged.
Now, I recognize that not all instances of this issue rise to the level of security problems. For less severe problems it might be better to just let it slide. But even here, I feel that even if the OP knows what they're doing, someone else who reads the question later might not, and it's important to have a well-voted post with the question mentioning that something may not be appropriate most of the time.