(Removed the post from Meta and posting here on Meta SO instead, as per the response I received on Meta.) The SO question that got me interested in this type of phenomenon.
Minor caveat: It's not proven yet that this is a case of the XY problem, since OP has not yet responded to confirm or deny.
However, I am interested in the general approach to these sorts of questions, so I am going to assume it is a case of the XY problem for the purposes of my post.
The Y problem presented by the OP can very quickly be redirected to an already existing solution. At the time of writing, there are three close votes for just this reason.
Edit The question is now closed.
However, the X problem is currently still unknown. If the OP actually updates the question, we might see a different problem emerge that is not easily referable to a previously answered question. I'm worried about the precedent this sets. If we blindly refer OP to an established answer to the Y problem, we are implicitly stating that Y should be used as the solution (since it is a well established problem that has been approached and answered in the past). This also carries over to any future visitor who is looking for help with a similar Y solution, who will see that the past OP was immediately referred to the existing duplicate question.
It seems to me that we should prioritize confirming it's an XY problem before we close the question, to prevent implicitly calling Y a good solution to problem X. But that's my question to you.
Am I wrong about this?
How can we best approach this when it happens?
Note: I am not asking about posting an answer that helps with the Y problem. I see no issue with that (not every poster can realize something is an XY problem). I am asking about closing and referring the question, which disincentivizes OP (and future visitors with similar questions) from actually reevaluating the proposed Y solution.
Edit This addition comes from the comments.
I've had feedback that mentions that the OP is responsible for asking the right question. While I believe that to be true in general, I think the XY problem is inherently different in this regard. OP is blinded by the first solution he could think of, and not considering different avenues (potentially not even aware of their existence, maybe it's simply a temporary matter of fixating on the problem for too long).
There is more than enough precedent for this on SO already:
- Even if the OP asks directly about string concatenation, when it is clear OP is composing SQL queries, any answer that uses string concatenation receives downvotes for not considering the dangers of SQL injection. Stack Overflow holds the answer to a higher standard than OP is expecting.
- It is widely accepted to offer alternative solutions to OP and not adhere to the strict rules OP initially asked about. This is already the case and should not change. However, my current question here is about how blindly referring someone to the answer to the Y problem completely shuts out the possibility of getting the OP to reevaluate options and consider the X problem; so OP can maybe implement a different solution Z. If we already tell OP that "solution Y" is the best answer to the question (to a point where we disallow any other answer to still be given), we directly influence whether OP will look for better alternatives. Because a Stack Overflow answer is expected to be an expert's help (in the eyes of the OP), the OP is therefore incentivized to listen to the expert's opinion.
string + string
(which is what the OP asked about) because it opens the door to SQL injection. The principle is clear: a bad (but technically working) answer is still a bad answer. Similarly, the proposed Y solution is inherently not a good solution. – Flater May 18 '17 at 15:34