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

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?

share|improve this question
    
Relevant question: stackoverflow.com/questions/11989337/… –  Caleb Aug 17 '12 at 16:07
1  
@Caleb Thanks, I really needed more downvotes on that. –  ngmiceli Aug 17 '12 at 16:09
7  
If they're doing something in an unconvential way, and their reason for doing so is because they've discovered some weird edge case where the only way to achieve their goal is to do something unconventional, they most likely understand the situation well enough to realize that an explanation that they must do it that way is actually relevant to the question. –  Jim Aug 17 '12 at 16:12
2  
On the other hand, if they just say "I'm doing this, here is how I tried to do it, but it didn't work", they are asking for corrective guidance on their approach to a solution. That guidance could be "use the back of your hand", which is better than their attempt at using their face (or some other terrible idea), or it could be "Don't touch it. Hold your hand above it", which is a better approach than touching it, and thereby (usually) better than all variations of their original approach. –  Jim Aug 17 '12 at 16:14
3  
Another example of a question where the "do it right" answer is far more liked than the "do it as requested" answer: stackoverflow.com/questions/11546349/… –  Toomai Aug 17 '12 at 16:14
    
Related: meta.stackexchange.com/questions/93872/… –  Al E. Aug 17 '12 at 16:58
    
Related: meta.stackexchange.com/questions/108343/… –  Al E. Aug 17 '12 at 16:58
    
@Caleb that was sad for me. I posted regex and filter_var before that guy (at least I think it was that question) and got -2 if I recal correctly before deleting it. It's true. What if their boss says "f*ck the standard lib! Use regex because it's powerful" –  Cole Johnson Aug 17 '12 at 20:03
    
@Cole if it was that question you would still see your delete post in red. You must be thinking of another. If you included both solutions with a proper explanation for why one was superior i doubt you would have gotten down voted. Also, that would be time to get a new boss. –  Caleb Aug 17 '12 at 20:28
2  
Regarding 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. –  mario Aug 17 '12 at 21:38
    
@Caleb yep that is the one I was down voted on. It's deleted so I can't see it –  Cole Johnson Aug 17 '12 at 22:27
    
@ColeJohnson: Deleted posts are not permanently removed, they are marked as deleted and hidden from most viewers. The owner of the post (you) and anybody with 10k+ rep would be able to see it still. The fact that you don't see it means you have the wrong question. You would still be able to see your own answer highlighted in red. –  Caleb Aug 18 '12 at 10:00
    
@Caleb after I delete an answer I refresh the page and can't see it –  Cole Johnson Aug 18 '12 at 19:54
    
@ColeJohnson: Some posts are automatically scrapped if deleted, but the rule only applies if you delete something within the first 5 minutes of posting, and doesn't have any votes or comments. –  Caleb Aug 18 '12 at 20:02
2  
Related: What is the XY Problem? –  todofixthis Aug 24 '12 at 2:15

9 Answers 9

up vote 17 down vote accepted

There are cases where the answer to a question is "You are doing it in the wrong way," followed by an explanation on what is the correct way.
For example, if somebody asked how to change the content of a module that comes with Drupal, I would say that is not what should be done, and I would explain how to override a function provided by a Drupal module. I would not answer to the question asked, in that way, but I would tell the user what s/he needs to do.

In your example, a better answer would have shown a regular expression to match a valid email address, explained if there are valid email addresses that are not validated from that regular expression, and said that the better way is to use filter_var().

It is true the user could have a good reason to use regular expressions instead of filter_var(), for example because the code needs to run on a site still using a PHP version lower than 5.2.0; if that is the case, s/he should have stated that in her/his question.

The fact the answer saying to use filter_var() has more up-votes is probably because users prefer not to use regular expressions when it is not necessary. Imagine if a user wanted to know a regular expression to remove spaces at the beginning, or end of a string; the natural answer would be to use trim(), and that answer would probably be up-voted more than an answer suggesting to use a regular expression as requested from the OP.

share|improve this answer

I think that most of the time, when question askers are aware that they are not using the best tool for the job, they explain why not. Generally, when they do not explain why, they aren't aware; or at least, if they are aware and don't say so, then they really haven't put enough effort into the question, and (frankly) deserve whatever pedantic responses they receive.

My personal tendency is to answer the question as asked, because that's just how my mind works. But I've been stung a couple of times as a result -- and I actually think that's a good thing. It's important that a site like this point out the potential pitfalls of a particular approach, and I've learned to read questions with a slightly more critical eye over time. I still generally answer the question as asked, but I usually add a caveat, or suggestion that the asker try a different approach.

More generally, I'd say that on balance, I'd rather have a site that is a bit pedantic at times than have a site that encourages the proliferation of bugs!

share|improve this answer

The best solutions to this I have seen is to answer a users question first and foremost and then warn them about the dangers of what they are doing.

Take a look at this answer I gave a while back about a MySQL driver call on PHP. First I attempted to answer the posters question as directly as possible.

After I did that, I mentioned the dangers of using MySQL driver queries and recommended MySQLi driver, or PDO_MySQL driver. For all I know this user was under a very strict environment, and could only use the MySQL driver; if they aren't, then (hopefully) they learned why the MySQL driver is bad, and moved onto MySQLi, or PDO_MySQL.

share|improve this answer
    
This is the method I try to follow. Answer the question asked, then inform them not to do it that way followed by pointing out the right way in closing. –  jschoen Aug 17 '12 at 16:12
2  
To me this does depend on the question though. If it's unlikely that the direct answer is helpful, but still reasonable, or not that harmful, I usually do this. If the direct answer is actively harmful (i.e. stove example) I will either put the preferred approach first, and the direct answer second (for emphasis) or actively tell them that there is a direct answer and I've chosen not to provide it because of (...). –  Servy Aug 17 '12 at 16:17

One important thing to note is that users asking questions here aren't actually looking for an answer to a question so much as a solution to a problem. The question the ask, the way they word it, and the details they include/exclude all amount to their representation of the problem.

A good answer does more than just answer the question explicitly asked. To write a good answer, you must understand the problem the asker is actually facing, and be able to solve that problem. A lot of times, the question lines up well with the problem, and a simple answer to the question is a valid solution.

However, there are many cases where the question doesn't communicate the problem clearly, or the problem the question addresses is actually a piece of a larger problem. The first order of business in these cases is usually handled in the comments on the question - clarification of what the asker is trying to do, how they are trying to do it, and why (as well as why they are taking that approach).

The next step is to provide a solution to the problem the asker is actually facing. That problem may very well be the user's lack of understanding. If I suddenly started working on a Ruby project tomorrow, I'd have little to no clue what I was doing. The first problems I encounter are more likely to be caused by me not understanding the language or the frameworks, and not knowing the common tricks and pitfalls. An explanation of a rule or pattern is more helfpul than a simple "change this foo(x.y) to bar(y.z) and it will work".

The Stack Overflow community understands this. That's why your answer, while addressing the explicit question, is scored lowly, while the answer that says "don't do that" has been upvoted. People vote based on the quality of the content, not how accurately an answer aligns to a question.*

*This statement is a generalization. I don't really know how each and every user on the site votes.

share|improve this answer

We cannot control how people vote on question answers. That is completely up to them. Often times the best answer to a question is a question that better informs modes of thought. Not all questions require a response that concretely answers the question asked. In your specific example, I don't believe that you should be penalized for offering this answer, but neither do I think the person who was less concrete should be penalized. But that just brings us back to my original statement that despite your answer being valid, we can't control the way users vote.

share|improve this answer
1  
I'm not so concerned with voting, as the appropriateness of answering people with "don't do that, do this" when that wasn't asked. The voting is merely a heuristic to judge my opinion against the communities –  ngmiceli Aug 17 '12 at 15:56
2  
Then in a sense it does answer your question by example. Multiple answers are allowed and are often more helpful when they inform the question instead of answering it. –  Conner Aug 17 '12 at 16:00

That question provided a problem and the technology available. The other answer provided the correct solution. Your answer provided something that will break and lead to problems without pointing out the issue it raises. I think it deserves the down votes as not helping people learn the solutions to their problems.

In general answers should address the problem as asked, but the other answer fits into the scope provided by the question. The didn't say "use jQuery", they used the technology specified in the way it was designed, alerting them to an issue they need to be aware of.

share|improve this answer
    
Perhaps it was a poor example then. There are plenty "use jQuery" questions as well, and more than often enough I'm tempted to use one. (Usually in the form of "use knockout.js and less jQuery) –  ngmiceli Aug 17 '12 at 16:14

The user might not always know what they are asking for. Sometimes people just add "buzzwords" to their question, but don't always know what they are talking about. Or, sometimes people's "requirements" are just wrong.

If you answer solves the issue, feel free to post it. Alternative solutions are always welcome, though you should describe why that solution is better than what the OP was trying to do originally.

share|improve this answer
1  
I can't count the number of times some unfortunate asker includes a few buzzwords and people jump all over it, either castrating them for suggesting using some awful technique or provides examples of the technique when it's clearly just not appropriate. Some critical thinking on the part of the reader goes a long way here. –  Servy Aug 17 '12 at 16:21

Context matters for this, I don't think it's a generally-answerable question.

If I believe my answer is significantly different than what they're explicitly asking, I might ask via comment if they're entertaining alternative solutions, or I might ask why they're trying to do a certain thing, as there may be a significantly more appropriate way of going about it.

If I believe the OP might not be aware of something, I might answer with an alternative solution, but clearly label it as an alternative solution if such-and-so condition doesn't actually apply. For example, a user asked about a Struct, I replied with an alternative using OpenStruct.

Otherwise I'll generally stick to the asker's script, but may interject alternatives in both technology and approach "below the fold". With only occasional "If you were doing this in jQuery you'd be done"s.

share|improve this answer

IMHO First answer the question asked, then address issues, not the other way around.

If I ask how to Foo the Baz, don't tell me it is easier to Bar it until you've addressed the Foo solution (perhaps by saying you're not going to attempt the Foo approach).

Of course, there's also non-answer related topics, which need to be careful not to receive upvotes before true answers do, otherwise the actually unanswered question receives fewer views. Clearly they should be comments, but if important or detailed enough to be answers, preferably added after true answers have been upvoted or accepted.

share|improve this answer

You must log in to answer this question.

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