17

In the answer from Colombo to this question, they provide a comprehensive general answer and suggest that the original poster can work out the solution from there.

R newbie asking about loops

I commented suggesting they give a full solution (though my comment was a bit poorly worded in retrospect).

My understanding was that Stack Overflow answers should be specific and complete given the purpose of SO as a repository of high-quality Q&As. It is not so concerned with learning.

My question is:

Should users answer the question in the specific, or is a general answer acceptable?

I looked for duplicate posts and could not find one on this exact topic, and the answering page didn't speak to it specifically in my view.

5
  • 1
    Is the answer likely to be useful to future visitors?
    – khelwood
    Commented Feb 12 at 21:30
  • 1
    @khelwood yes, I think it is likely to be useful to future visitors. I upvoted the answer and I think it is useful, only it stops short of providing a specific solution for the OP and I wondered if that is an issue (I had understood it to be in the past, but may be wrong).
    – Jay Bee
    Commented Feb 12 at 21:37
  • 2
    The answer that I posted contained all the techniques that solved OPs problem. It wasn't just a code that OP could copy-paste as their solution.
    – Colombo
    Commented Feb 13 at 0:36
  • Ideally an answer should contain the minimal reproducible code that answers the question. The code should be tested or it is not strictly reproducible. I guess this means the answer should be specific.
    – MT1
    Commented Feb 13 at 20:49
  • I'd say any answer has to at least easily answer the question as asked... if OP can't relate the answer to the question then its not an answer IMHO. But of course the more long term value it can provide the better.
    – Dale K
    Commented Feb 15 at 4:48

6 Answers 6

28

The best answers are BOTH!

You really have two audiences. The first is the person who asked the question, and their scope is limited - they came to the site because they have a specific problem they're trying to solve. If you don't solve their problem, you've failed.

The second audience is the horde that will find the question long after it's been asked, through a search engine or a link from another part of SO. Their situation specifics will probably be different than the original, so the answer needs to be broad enough to anticipate those.

4
  • "so the answer needs to be broad enough to anticipate those." Citation needed. Since when is it a rule (re: "needs to be") for answers to address unknown future readers' needs?
    – TylerH
    Commented Feb 14 at 14:48
  • 12
    @TylerH it's not so much a rule as a goal, as that's the goal of the site in general. You'll notice that I started with "The best answers...", not all answers on the site rise to the level of "best". Commented Feb 14 at 15:57
  • @MarkRansom Right, I wasn't asking for a citation for your 'best answers' comment. I was asking for your final sentence where you state "the answer needs to be". Perhaps you meant "ought" or "should" or something different?
    – TylerH
    Commented Feb 16 at 15:52
  • 2
    @TylerH to clarify, my statement was that the answer "needs to be" if it is to be considered a really good and complete answer. Obviously not all answers will be, and that certainly doesn't mean they aren't useful. I stand by that statement as worded. Commented Feb 16 at 16:55
10

Yes, answers should always answer the question that was asked. No exceptions[1].

Bonus points if an answer goes above and beyond, such as explaining how to apply the same thinking or code to other scenarios. But those points are just that: bonus.

[1]. you may ask about XY-problem questions; in those cases, you are hopefully confirming with the asker first that they're really trying/asking for something else first before answering/solving for that other thing. Making an assumption that someone is asking for Y when they have asked for X without verifying is still bad.

20
  • 5
    I don't think this is quite right. Occasionally a question is asked that is the programming equivalent of "How do I turn screws using my hammer?", and it's obvious that the answer is "you can't, but let me describe how to do it with a screwdriver instead". Answering the question literally as asked would be madness. If I suspect an XY problem I just go ahead and show how to do X, state that I suspect they actually want Y, then show Y. Trying to clarify it's an XY via comments is lengthy and often fruitless - a clear demonstration via an answer is less frustrating and almost always useful. Commented Feb 13 at 0:20
  • 2
    @AllanCameron you're right... but in your scenario the question needs to change first. Form an X/Y problem into a proper question.
    – Gimby
    Commented Feb 13 at 10:19
  • 3
    @Gimby an XY problem can be a perfectly reasonable question without being rewritten. Take for instance: "I have lots of strange data-containing strings in the format "{\"foo\":\"bar\"}", and I want to extract "bar" using regex." Ignoring the fact that this would actually be closed as a dupe in most contexts, a direct answer would be to show the regex solution in the relevant language, but a better answer would be to show the regex followed by a solution involving JSON parsers. Commented Feb 13 at 11:58
  • 1
    @AllanCameron I don't care what is perfectly reasonable, the only thing that matters is what is on-topic for Stack Overflow AND what will be regarded as good quality. If an answer does not directly answer the question asked but it does provide what the author was seeking, the question is not good enough quality for Stack Overflow - a knowledge base, not a helpdesk. Rewriting would be highly recommended to prevent downvotes.
    – Gimby
    Commented Feb 13 at 12:56
  • @Gimby I completely agree, it's not a helpdesk, it's a knowledge base. And I apologise for my imprecise language - when I said 'perfectly reasonable' I meant it exactly in the sense of on-topic, high quality and helpful. I have seen many excellent (on-topic and helpful) questions that arose from minor misapprehensions on the OP's part, and those same misapprehensions will happen to other folks in the future, making the Q&A an excellent resource for a common problem. The ability to see past the literality of a question is one reason why SO is still way better than LLMs. Commented Feb 13 at 13:47
  • 1
    @AllanCameron Your example answer does answer your example question; "no" or "you can't do that" is a valid answer and one that is perfectly acceptable on Stack Overflow. That being said, I already address the rest of your concern in my answer, regarding XY questions. That you personally feel dealing with XY problems is unfortunate, but also irrelevant, as it's still how everyone should address XY problems, site-wide (and, luckily, many (most?) folks do have a fine time dealing with them).
    – TylerH
    Commented Feb 13 at 14:12
  • 1
    @TylerH I don't think I've ever seen an answer as curt as "no" or "you can't do that" that anyone has upvoted as being helpful, but maybe you're right about that. My point is that SO is a repository of programming knowledge, and folks will often get stuck with a problem that is expressed in such a way that an answer-exactly-as-asked will completely miss the point, yet the same question will occur to several others in the future, so the question as asked will be findable and useful. I just don't think the no exceptions intensifier is true in this collaborative human endeavour. Commented Feb 13 at 14:50
  • 2
    @AllanCameron You seem to be reading only one part of the answer here. Note that I also say in the answer that it is good to add more information that helps users beyond what they asked for. Let me provide an example: a question asks "how do I foo the bar in Swift for iOS". Someone answers "here's how to do it in Objective-C" because they know it's not possible in Swift but Objective-C will probably be OK for OP's ultimate needs. That answer is helpful, but it doesn't answer OP's question. It is magically, simply, easily fine if it's just edited to also say "you can't do that in Swift."
    – TylerH
    Commented Feb 13 at 15:05
  • 1
    @AllanCameron That small line is critical, not just because it's what directly answers OP's question, but also because it helps explain why someone is answering in the wrong language. Otherwise, such an answer risks getting downvoted/flagged/deleted for apparently not answering the question or even using the correct language.
    – TylerH
    Commented Feb 13 at 15:06
  • Yes, I agree with that @TylerH. Maybe we're saying the same thing in different ways. Commented Feb 13 at 17:05
  • 8
    Agreed. Stack Overflow is not a school. Busy professionals ought to be able get some immediate value out of it without having to resort to guesswork or solving puzzles. There are more than enough puzzles in existing code. Commented Feb 13 at 18:35
  • 2
    @Wyck Not sure what you mean? My answer directly answers the question that was asked. There's no irony there.
    – TylerH
    Commented Feb 14 at 14:47
  • 1
    @MichaelKay No, there are problems with every single scenario in your rebuttal. If a question doesn't make sense, it should be closed. I'm not sure what you mean by "there is no answer"; there is always an answer, but maybe you're thinking of when the question doesn't have an objective answer, or when you'd have to ask the an authority (e.g. "why did language X do Y this way?")? If so, those questions should be closed as opinion-based. If there's not enough information to give a whole answer, ask the OP for more information and/or close the question as needing detail.
    – TylerH
    Commented Feb 15 at 22:42
  • 1
    @MichaelKay cont'd: If you don't have time, don't post an answer yet. Such "Fastest Gun In The West" answering is in fact discouraged on Stack Exchange because it often leads to poor quality answers like you suggest. If someone is asking a question that requires a heavy load of education/learning, close the question as too broad/needs focus.
    – TylerH
    Commented Feb 15 at 22:44
  • 1
    @MichaelKay "That's not possible" is a valid response that directly answers the question "How can I do this", as mentioned I think a couple of times above. It's not something that runs afoul of my guidance. Telling the user how to do it in 1.1 would be, as mentioned in my answer, bonus points.
    – TylerH
    Commented Feb 16 at 15:21
9

There isn't even a hard requirement that you fully answer the question when posting an answer. https://stackoverflow.com/help/how-to-answer

Any answer that fully addresses at least part of the question is helpful and can get the asker going in the right direction. State any limitations, assumptions or simplifications in your answer. Brevity is acceptable, but fuller explanations are better.

There is nuance, such as answers that are just links where the link itself isn't the answer being a no-no. But I really don't see why generalizing a question and answering that should be wrong in some sort of moral sense, and I'm not aware of it being disallowed as a rule. I do it sometimes (answer generally). But again, there's nuance. For example, when people post ChatGPT answers (which is not allowed), it's often a list of debugging / troubleshooting tips that are more on the general side. I have done something like that on rare occasions, but it doesn't leave a great taste in my mouth considering that the point of SO is (as I understand it, generally) that you ask a well-scoped question and get an answer dedicated for that question.

4
  • There isn't even a hard requirement that you fully answer the question when posting an answer. That nonsensical rule relaxation was imposed long after the site's original rules were codified, by a Stack Exchange Inc. deliberately abusing the "be nice" initiative to allow more rubbish and thus pump up user numbers (sound familiar?). The fact that one of the longest-serving moderators on the network had to come up with an incredibly convoluted explanation, involving images of fruits, to justify this rule should trivially indicate how ridiculous it is.
    – Ian Kemp
    Commented Feb 14 at 21:06
  • 2
    A list of general tips can be good (and highly useful, for example, Boot loader doesn't jump to kernel code is one of the most linked [x86-16][bootloader] questions because most of those mistakes are non-obvious and common). But only suitable for an SO answer if there's also a separate section to the answer that answers the specifics of this question. That's the part ChatGPT leaves out (at least the way polluters use it), which is one of many ways in which its answers are usually low quality. As well as ChatGPT's general tips being too general. Commented Feb 15 at 5:15
  • @IanKemp I respectfully disagree. To me the crux is that an answer helps the user along the path to solving their problem, not that it fully answers the question. For example they may ask for code that does X, and show you their best attempt; telling them why their best attempt doesn't work is a partial answer and in my view is entirely acceptable; you don't have to give them the working code that they asked for. Commented Feb 15 at 22:46
  • 2
    @MichaelKay I'd say ideally, a good answer would. or the other way around- it would be good because it did that. that's what separates SO from r/learnprogramming, which is expressly a "teach to fish- not give a fish" place.
    – starball
    Commented Feb 15 at 22:48
7

Give a man a fish, and you feed him for a day; teach a man to fish and you feed him for a lifetime.

I generally prefer helping the OP solve the question themselves, over spoon-feeding the solution.

So, pointers where a user is making mistakes, keywords the user should look into, techniques he should be using instead, that kind of help is (IMHO) much more valuable than just handing them the fixed code.

That said, you need to take care that you actually answer the question.

13
  • 4
    "teach a man to fish and you feed him for a lifetime." The relevant aspect of this is that when learning how to fish you typically catch a fish, which means the man's immediate need is also addressed: they're hungry and need a fish.
    – TylerH
    Commented Feb 12 at 21:57
  • 3
    I see you are starving, here is a copy of Fly Fishing by J R Hartley.
    – Fraser
    Commented Feb 12 at 23:25
  • you feed him for a lifetime. This may only be true for another generation. Two if we're lucky. Commented Feb 13 at 0:22
  • 5
    I... can't really upvote this. This is true on any other website, but we're on Stack Overflow. Help the many, not the one. Bla bla bla. What you describe is essentially mentoring.
    – Gimby
    Commented Feb 13 at 10:21
  • 4
    @Gimby The pointers about what the user was doing wrong can be equally helpful for other readers, if not even more so, compared to an answer tailored specifically to the OP's exact usecase. But you're free not to upvote :D
    – Cerbrus
    Commented Feb 13 at 14:30
  • I try more and more to do both, give a working solution for the user and give pointers where something went wrong or could be better in the future so the OP and future others can learn from it and stop making the same "mistake". Commented Feb 14 at 9:33
  • 5
    "Build a man a fire, and you keep him warm for a night; set a man on fire, and you keep him warm for the rest of his life." Wait... what were we talking about? Commented Feb 14 at 17:01
  • 1
    The kind of help you mention belongs in a comment, not an answer.
    – Ian Kemp
    Commented Feb 14 at 20:42
  • 1
    @IanKemp No. It's not that black and white. It's perfectly possible to answer a question without directly spoonfeeding the solution. I also feel like you're ignoring the last paragraph of my answer.
    – Cerbrus
    Commented Feb 15 at 7:20
  • 1
    While teaching is a noble act, if your answer doesn't directly answer OP then you run the risk that OP doesn't have time or intention to learn and may down vote your answer and give the cred to the first poster who takes your teaching and applies it to the OP. Commented Feb 15 at 20:58
  • 1
    Getting the green tick from OP will help give you a platform to teach those who do search for this in the future. Commented Feb 15 at 21:00
  • @ChrisSchaller "Run the risk"? Are we here to help people, or to earn brownie points? Commented Feb 15 at 22:53
  • The more votes your answer gets, the more views and the more people you will help. Big tick helps get those votes. If you really want to help, then you have to play the game. I don't necessarily like it, but that's the way the community works. Commented Feb 16 at 6:08
1

The answer as to whether answers should be specific or general, is the same as the site rule as to whether questions should be specific or general. An excerpt:

Write a title that summarizes the specific problem

(emphasis mine)

A more general answer may be more useful to more people, and it may be a better teaching aid, but we are not here to teach; we are here to answer. The expectation is and always has been that those who stumble upon an answer at a later stage are competent enough to use it as a learning opportunity, not that answers must inherently (attempt to) educate.

0

For questions that are well asked, there won't be a dilemma. This one wasn't, and should not have been answered at all. But if you look at better questions on the site (I would say higher-rated, but you have to consider that older questions were held to a different standard), you'll find that they overwhelmingly don't have this problem - because the requirements for a good question more or less prevent the problem from coming up.

"R newbie asking about loops" isn't a suitable question title, because it doesn't allow anyone to search for the question. It's talking about the OP rather than the question. It doesn't describe the question in any meaningful sense. It's not even evident whether the question should be a "how do I do X?" question or a "why did Y happen?" question (the two main categories that encompass almost every valid question).

We can't answer "can anyone help with a loop for the above command?", because that is not a proper question. It doesn't tell us what kind of help is needed.

The question also suffers from the classic problem of being confused between the two categories I outlined above.

If it's intended to be "how do I write this loop?", then the existing attempt is not relevant. What we need is a clear description of what problem needs to be solved. If it's about how to make a loop for this situation, then it should explicitly say that - but it also needs to explain what "this situation" is, in a searchable manner. If it's about a technique for analyzing code and producing the corresponding loop, similarly that needs to be made explicit, and focused enough that an answer can be written.

But if it's a how-to question, it's one of those and not the other. And as such, there is no problem choosing how to write the answer. The code-seeking question gets code; the technique-seeking question gets a technique.

On the other hand, if the overall question is intended to be "what's wrong with this attempt at the loop", then we simply don't accept "here's my attempt; it didn't work". We don't provide a debugging service, and we expect a specific question. That starts with the OP being responsible for analyzing what happened when the code was tried, beyond just "it didn't work"; proceeding to follow standard debugging steps, and finally producing a proper MRE of the problem so that a concrete question about that problem can actually be asked.

As it happens, the question was closed as a duplicate of a better-written, but still far from ideal question. At least here we can see a clear description of the problem, and a clear explanation of what went wrong with the attempt (although the question should still have only one of those things). We also see a title that concisely summarizes the problem: "subset multiple data frames based on the same condition". Ideally, that question would be edited; or perhaps someone could prepare a self-answered version that asks is properly, and everything else can be dupe-hammered there. (It's a well-known problem that the people who need this kind of information, lack the perspective required to ask the question properly.)

4
  • 1
    I don't see an answer to this question, in this answer... Should answers be general or specific? You've written a lot about how questions should look...
    – Cerbrus
    Commented Feb 15 at 9:20
  • @Cerbrus I answered it in the first sentence: "For questions that are well asked, there won't be a dilemma.". The rest is explaining how, in the general case, asking questions properly avoids the dilemma - implicitly, by showing how asking them improperly causes the dilemma. I assume you are familiar with the concept of a frame challenge. Commented Feb 15 at 9:23
  • @KarlKnechtel For a perfectly posed question in the format "How do I do X?" it seems an answer could be general (e.g. using built-in data frame iris I will demonstrate the concept you need to apply to get a result) or specific (this exact code snippet will get the output you want). My question is which of these formats is suitable for SO.
    – Jay Bee
    Commented Feb 15 at 10:30
  • 1
    Well, very many questions tend to take the form "I want to do X. I tried Y, and it didn't work", and as answerer you have the choice to focus either on how to do X, or on why Y doesn't work. In my view the question is clear, and both kinds of answer are equally acceptable. In an ideal world of course you do both; but you might not have the knowledge or time to achieve that. Personally I find answers that give the required code without explaining where the OP went wrong rather unsatisfactory, although in a literal sense they answer the question. Commented Feb 15 at 22:58

You must log in to answer this question.

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