19

I refer to Reason why I can't insert a comment inside the HTML tag?.

This question asks why comments can be placed in HTML tags. The OP gave the example of trying to place <!-- --> comments inside an image tag, which everyone responded was impossible, of course. I suggested that if he was using a templating language, in most cases he could use template comments inside a tag, such as <img {{! comment }} src="foo.jpg">.

One highrep gentleman took me to task for going off topic, saying that the question was obviously meant to be about HTML comments inside tags, and there was no mention of templating languages in the question, and my answer was not an answer, and was polluting the SO Q&A repository with off-topic answers.

My assumption was that the OP was at heart saying he wanted to somehow put comments inside HTML tags, tried using HTML comments, found they didn't work, and wanted to know why, but the underlying problem was if there was some way to place comments there, and my answer was a reasonable (the OP even commented "interesting") solution.

Another example: if a question asks for a regexp, and is tagged regexp, but there's a better non-regexp solution, is it off-topic to suggest that?

In another case, a question asked about some JS computation. I suggested an Underscore solution. Another member commented that since the original question was not tagged Underscore, that my answer was out of line ("not an answer"). I certainly understand people having trouble with jQuery solutions being proposed in non-jQuery contexts, but I think Underscore falls into a different category. It's a lightweight, robust, widely-used toolbelt that the OP might not know about.

So my question is, how rigorously are we to read questions and their tags; are they to be taken literally, or how much room is there for an interpretation?

4
  • 9
    This is going to be case by case specific, but it's clear in the linked post that the OP found your answer useful based off the comments. Answering is based on a users interpretation of a question, some will be on the money some won't, that's where votes will play their part. If it helps the OP then that's all that really matters, votes and comments aside.
    – Tanner
    Oct 15, 2014 at 11:11
  • 4
    @Tanner: As SO is not a help-desk, but strives to be a collection of questions and answers for all programming-problems one might encounter, helping the asker is far less important than polishing the question until it is clear and of acceptable scope, and answering that well. The asker is, or should be, only a miniscule part of the audience your answer helps. Oct 15, 2014 at 16:05
  • 1
    I would recommend staying away from suggesting alternate frameworks/languages etc due to the fact that it's of no use to future users who find a question similar to their problem. If a user has a jQuery question and finds a promising question on SO but the solution ends being totally unusable because the answer is to use a different framework, that question can't be the canonical answer, which is what should be on SO.
    – kylieCatt
    Oct 15, 2014 at 22:38
  • I would note that if you are unsure whether the OP is open on the scope of solutions or not, you can always ask her via comments to specify whether such and such framework/approach is to be considered in her case. Oct 16, 2014 at 12:00

1 Answer 1

8

Yes, answers should take questions rather narrowly and help with the exactly problem that was stated.

It is not wrong to use/suggest additional frameworks that simplify the answer, even if the OP has not asked for them - as long as they do not obscure the solution.

E.g. when someone asks "How to write a script that toggles XY on press of a button", no one would subject to use jQuery in a demo, as the answer is "use event listeners". However, if a user asks "How to install an event listener" and the question is not tagged [jQuery], then it would be wrong to answer with a jQuery-only solution.

Other example, when someone asks for an "algorithm to transform one data structure into some other", it is fine to use the functional programming primitives that Underscore offers in the answer (as long as the question cannot be answered with a single Underscore method, where the algorithm is hidden in the library). However, if he asked "how to iterate an array" it would be wrong to present _.each.

Of course, it makes an answer more valuable if you amend the solution with a suggestion like "this code could be simplified by using library XY which does approximately the same thing".

If the question asks for "parsing XTHML with regex", it is both a valid answer to state "cannot be done [easily]", explain why, and suggest a better alternative, as it is valid to provide a huge complex regular expression that does the task. Similar things are done very often to string processing questions, where the user states his problem and the language to use and expects a regex solution, so he does tag it [regex]. In case of such XY problems the tag should be ignored and the alternative solution that helps the user should be presented - unless the OP specifically states his need (which can be academic interest as well) for using regex.


In your specific case, I think your answer is questionable. As you say, you [assumed] that the OP was at heart saying he wanted …. That's not really what was asked for, the question is stated quite clearly. He does ask for "the reason why I can't insert a comment inside an HTML tag" and a detailed explanation of this behaviour. The only interrogative pro-adverb in text and title is Why, not How.

So, if you answer that question and then suggest a workaround (like using a templating language, or any spits-out-HTML-preprocessing-language), it would be good. The suggestion alone should be rather a comment than an answer, however.

You must log in to answer this question.