I, personally, am a fan of answering the question asked verbatim, whether or not it seems to be the best approach to the implied problem.
For example, a question asked for a regular expression to validate emails, and tagged that question with php
. The second answer clearly explained that one should not use regex in PHP, and should always default to filter_var
, and had a score of +8/-0.
My opinion was that the user didn't ask, "should I use regular expressions", he or she asked, "help me build one." I answered the question by providing them with some solid regular expressions meeting the requirements, and received a score of +2/-2 with a comment "this is sad..."
Edit: Let's not focus too much on this specific example. We have all seen the questions that ask for a solution in Javascript and mention jQuery, or want a way to search the file system in Java and someone says, "this makes more sense for a scripting language."
Now I understand that there comes times for answers like this. If my son (no, I am not yet a father) asked me, "Hey Dad, which body part should I press against the stove to see if it is hot?" I would answer, "You shouldn't, you should hold your hand over it." And I would be a good father to do so, rather than "the back of your hand; it's the most sensitive to heat". We want to see people avoid being burnt by going down the wrong route to solve a problem.
But we're not all children here. Perhaps the OP had a perfectly good reason to need a regular expression instead of filter_var
. Maybe they came upon some strange edge case that they didn't bother to explain because it wasn't relevant to the question. Should we not trust them to handle the stove as they see fit, and answer the question asked? In my opinion, the suggestion to filter_var
is a comment, not an answer.
But alas, I am the one with a net score of 0, so I ask -- when is it appropriate to answer a question that wasn't asked?
filter_var
- it does use a regex internally. Should that answer be a one-liner however (oh, you, use filter_var), then of course, it's nothing more than a comment, disqualified for the answer box.