28

I was just attempting to answer questions when, right before I posted my answer, this answer was posted.

This reminded me of a conundrum I've been pondering about for a long time in Stack Overflow: Are short, self-evident answers (for people who know the language) without any explanation acceptable? This also applies to my answer, since I'm not sure if I need to explain the list comprehension more clearly.

And no, I am not asking this because our answers are competing - I actually upvoted the other person's answer. Sportsmanship for the win!

Here's a made-up example of such an answer:

The answer to your question uses a while loop:

while (True):
   if (x):
       break

If you understand Python, this code above is pretty obvious, but if you don't then it may be tough to understand.

The reason this issue bothers me especially is the review that I mentioned in this Meta question. The answer I reviewed there was the same kind of thing - provided the right answer, was self-evident to those who knew the language, but had little to no explanation of the code. This led me to put a comment there (which resulted in my review ban but anyways).

Anyway, to conclude my question is: Do good answers require an explanation?

EDIT: My answer just got accepted. I guess an explanation really does make an answer better!

27
  • 5
    define good... it's certainly possible for an answer to be useful without an explanation. Does an answer that is useful qualify for being "good"?
    – Kevin B
    Commented Mar 12, 2021 at 21:41
  • 2
    @KevinB When I say "good", I mean good enough that no one should be asking the poster of the answer to make any changes. Basically, was I justified in asking for an explanation in the reviews?
    – M-Chen-3
    Commented Mar 12, 2021 at 21:42
  • 1
    it's always appropriate to suggest improvements or request clarification
    – Kevin B
    Commented Mar 12, 2021 at 21:43
  • 8
    That's up to the OP, so i'd hazard a guess, based on the poor quality of some of the answers i've seen accepted, that the bar for that is quite low for some people.
    – Kevin B
    Commented Mar 12, 2021 at 21:54
  • 2
    the real question: do people really need explanation with a working code? unfortunately, for many it's a NO. give me a working code that I can copy past fast please is what most of the asker want Commented Mar 12, 2021 at 22:08
  • 18
    An answer with some explanatory text is almost always preferable to a code-only answer. The explanation can be in the form of code comments, but it's good to have some plain text explanation too.
    – PM 2Ring
    Commented Mar 12, 2021 at 22:11
  • 8
    It's the curse of the slower answerer. While working to explain things and checking that everything is fine, someone else will post a mostly code only Answer and get a higher score on their post.
    – Scratte
    Commented Mar 12, 2021 at 23:07
  • 10
    @Scratte Yes. But according to SO we are to believe that the best answers will accumulate the most votes over time. Just how long that time period is...... If the idea is to provide the answer of most use to potential future readers, however, then it seems self-evident an accurate answer with detail is more useful.
    – QHarr
    Commented Mar 12, 2021 at 23:27
  • 2
    @QHarr That sound so nice and it's how the system is suppose to work. Unfortunately it doesn't account for the score-feedback-loop, which "over time" causes the highest scoring posts to accumulate more votes ;)
    – Scratte
    Commented Mar 12, 2021 at 23:53
  • 3
    @QHarr "But according to SO we are to believe that the best answers will accumulate the most votes over time. Just how long that time period is......" about 6-8, obviously
    – VLAZ
    Commented Mar 13, 2021 at 1:19
  • 1
    Hmm, you ask us about "good" answers but then show a bad one as example?
    – Manuel
    Commented Mar 13, 2021 at 2:57
  • 4
    I'd say, especially when using a language like Python, which is full of magic and in no way obvious, it sure does help to give a summary of what's really happening.
    – Sederqvist
    Commented Mar 13, 2021 at 4:12
  • 3
    Of course good answers require explanations. Stack Overflow is an example of community-based co-education. We can't - and we shouldn't - assume a level of prior knowledge on the part of the reader. Not least because a single answer may be read by thousands of readers, who will all have different degrees of exposure to the language(s) the question relates to.
    – Rounin
    Commented Mar 13, 2021 at 15:33
  • 3
    @PM2Ring I think I know how to teach stuff. I feel no need to cuddle the skill. And I'm not quite sure that you're right about higher reputation members are excellent teachers. I've seen those higher reputation posts containing "I guess this is what you want: <code>". Another one personally told me that fixing syntax errors is left "as an exercise for the reader". This conversation started with slower answerer's posts don't get a high score. Which by any metric means that thorough answerers need to post a lot more and their post take more time.. compared to quick answerers, that rise fast.
    – Scratte
    Commented Mar 13, 2021 at 17:40
  • 2
    "Victory needs no explanation, defeat allows none" ... but an answer could use some.
    – lfurini
    Commented Mar 15, 2021 at 9:04

5 Answers 5

62

Do good answers require an explanation?

Yes, yes they do.

If there was an obvious mistake in the asker's code, the question should've been closed in the first place as "not reproducible or caused by a typo". If the solution was easy (to an extent that one could read the code and get all the info they need), it is highly likely there is a suitable duplicate target, and the question should've been closed as well.

All other cases are in need of some sort of explanation. Either the problem is not that easy, or there is a relevant open issue, a pull request, etc. This should be decided on a case-by-case basis, but some explanation must always be provided.

I've seen some users insert explanations as code comments. These are special cases that may or may not constitute good answers depending on the usefullness of explanations (and unless the comments are correlated with code lines, they should be moved outside of the code block).

An answer is good if it can be an accepted answer as is

No, no it is not.

This is a definition of an answer useful to the OP (which is what an accept button is for), this does not automatically make it a good answer.

8
  • 1
    Thanks for the clarification. Evidently my standards for a good answer weren't accurate.
    – M-Chen-3
    Commented Mar 12, 2021 at 22:16
  • 4
    @M-Chen-3 - I just think you concentrated on answers themselves a little bit too much: maybe for a question "how to loop over X", an answer "here is how" is not necessarily a bad one (although a link to docs and a couple of alternatives like "use map()" would be nice to have). The problem is it is likely that such answers are redundant (unless the question is about an emerging technology) and shouldn't have been posted in the first place ( if they do not provide other value than literally answering the OP's question ).
    – 0Valt
    Commented Mar 12, 2021 at 22:48
  • 1
    @OlegValter I agree with your answer here, but have to disagree on "shouldn't have been posted in the first place". If it answers to a question that people have, possibly helping people in general (and is not a duplicate), I don't see why it shouldn't be posted? I don't think we have a policy that we only allow good answers, even though we do prefer them. It's up to community then decide if the answer is worth it or not, but I don't think we should pre-emptively forbid them.
    – eis
    Commented Mar 13, 2021 at 11:00
  • 1
    @eis I think you misread the quote a bit - it is about closing questions that are nothing more than simple typos - they serve no value for future visitors and should be marked as such - so as those who end up on the question due to search terms or whatever can save themselves some time. I also do not talk about premoderation of posts - censorship (in a strict sense of the word) is never a good idea. What I believe, though, is answering typo and basic questions (unless, as mentioned, the technology is emergent) does a disservice to the site in the long run and shouldn't be considered good.
    – 0Valt
    Commented Mar 13, 2021 at 11:14
  • 2
    @OlegValter You should have stopped after "Yes, yes they do." ;)
    – matheburg
    Commented Mar 13, 2021 at 12:02
  • 2
    @matheburg - that would contradict the whole point :)
    – 0Valt
    Commented Mar 13, 2021 at 18:43
  • 1
    Indeed, I have seen people accept outright wrong answers before. A checkmark is no indicator of quality.
    – TylerH
    Commented Mar 15, 2021 at 1:45
  • @TylerH - absolutely true. The accept checkmark seems more like a carryover from support forums indicating the "ticket" is resolved for the asker, and it tells nothing about the post other than it seemed helpful to the OP at some point in time.
    – 0Valt
    Commented Mar 15, 2021 at 21:23
20

See How do I write a good answer?

Answer the question

Read the question carefully. What, specifically, is the question asking for? Make sure your answer provides that -- or a viable alternative. The answer can be "don't do that", but it should also include "try this instead". Any answer that gets the asker going in the right direction is helpful, but do try to mention any limitations, assumptions or simplifications in your answer. Brevity is acceptable, but fuller explanations are better.

(added bold)

3
  • 4
    Hmmm... if you really think that explanations are better, then I think you should edit and add an explanation on why explanations are better. Commented Mar 14, 2021 at 16:33
  • @Lakshya Fair enough, lol. But this isn't really "my" answer, it's a community wiki to compile the existing advice from consensus. I posted my own answer to contain my own opinions.
    – wjandrea
    Commented Mar 14, 2021 at 19:00
  • 1
    Yeah, I saw your answer. I guess a community wiki would be fine without an explanation if someone else wanted to add an explanation :) Commented Mar 14, 2021 at 20:46
16

Yes.

As someone who knows Python pretty well, I would want an explanation for that made-up code:

while (True):
    if (x):
        break

Because IMO, it's not obvious. while not x: is obviously simpler, but maybe there's a non-obvious reason for doing it the way you did it. And why do you say "The answer" when there are obviously other ways to do it?

I might just be picking on a bad example, but my point is, even the simplest answers can be filled with assumptions, so in my answers, I try to give an explanation, with qualifiers for anything that's not 100% obvious. For another made-up example:

You'll probably want to use while not x:, but you could use

while True:
    if x:
        break

if that fits better with your existing code. Both loop until a condition is met.

(I would add an actual explanation in this example, but you haven't said what the question is, so it's hard to make up something sensical.)

14

The key as I understand things is to fully understand just who the target audience is for an answer.

It is the original poster, yes, but more importantly, it is also any future visitors who stumble upon the question searching for solutions to a similar problem, and in this situation, not only is textual explanation very helpful, it is key, because more than likely their code will differ significantly from that of the OP's, making a mostly code-only answer much less helpful.

So bottom line, write your answer for posterity, not just for now.

2
  • This answer is like a part 2 to Oleg's answer. If only I could accept two answers!
    – M-Chen-3
    Commented Mar 13, 2021 at 0:00
  • 5
    So bottom line, write your answer for posterity, not just for now. - Yes, otherwise preferably don't answer at all; that's a valid choice if the question isn't interesting enough to be worth writing a good answer. (Or go look for a duplicate.) Commented Mar 13, 2021 at 8:02
4

It depends on the question:

  • A question seeking understanding can only be answered with an explanation (optionally supported by code examples).

  • A question seeking how to do something is most clearly answered by code, optionally supported by an explanation that closes any gaps of knowledge that have prevented OP from finding the solution himself. However, sometimes the only gap is the name of the feature that solves OP's problem, in which case further explanation can be redundant.

While the latter is rare, it does occur. For instance, when somebody asked

How to I test if a is a subclass of b?

Class<?> a = A.class;
Class<?> b = B.class;

I answered:

Are you looking for:

Super.class.isAssignableFrom(Sub.class)

And received 3 times as many upvotes as an answer that provided a 4 paragraph explanation of this API element and when it might be used.

OP actually commented on this difference, writing:

Many thanks for the detailed answer; I'm accepting meriton's though, as it is the clearest IMO.

In this instance, further explanation only muddied the waters, making the answer harder to understand by burying the important nugget of information in unnecessary detail.

My answer worked for OP and the 264 people who cared to upvote, because the question already showed a correct understanding of all concepts involved. The only thing missing was the name of this confusingly named API element.

Usually though, OP will have gaps in their knowledge that go beyond a mere name, requiring an explanation.

Note that the above criterion doesn't just describe whether an explanation must be present, but also at what level of detail. If the question shows that OP understands little, we must explain more.

3
  • Which question did you answer? It appears to be a duplicate of this question.
    – M-Chen-3
    Commented Mar 14, 2021 at 21:30
  • Honestly, the fact that the question is a duplicate backs up Oleg's point, which is that if a question is so simple that its answer wouldn't require an explanation, it usually is a duplicate.
    – M-Chen-3
    Commented Mar 14, 2021 at 21:33
  • 3
    @M-Chen-3: My answer predates your duplicate by a year ... and even if such questions are duplicated more often, we want to answer them at least once, so the question of how much explanation that answer should contain remains relevant.
    – meriton
    Commented Mar 14, 2021 at 22:01

You must log in to answer this question.

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