12

Since SO is the platform for all and not the user who actually posted the question. So I follow the pattern of writing the answer starting with the best possible way to achieve that task. And later at the end of the answer I mention the actual issue with their code.

For example, consider the question: IndexError: list index out of range… How do I print every other item in a list without it giving me this error. Here user was trying to get the alternative elements in the array list, and increasing the count by 2. But he was iterating over the count of length of list. Hence code was raising IndexError as code tries to fetch the item more than the maximum value.

In my answer, I mentioned the actual issue at the end, and started with the best way to achieve the task.

So, my question is:

  • Should the answer start with the best way to achieve task? As SO is for all. It will be much more useful for someone searching for it in the future.
  • OR, Should I start with directly mentioning the actual cause of error and then illustrating the better way to achieve it? As thread was started by particular user, it will be much more relevant to the user. (knowing that starting my answer with index out of range issue won't be of much help for someone in future).

Most of the time I find myself in this situation while answering such questions.

2
  • 8
    Isn't that the entire difference between answering one person's question and teaching? I know: at times the OP complains "but I haven't learned that advanced stuff yet" – but others may have, and those are better served by having a better solution as well.
    – Jongware
    Nov 21, 2016 at 14:07
  • 1
    That's surprising that Python does not have canonical "index out of range" question... I though it is somewhat popular language... Is it because all people who used Python before had more expirience? :) Nov 21, 2016 at 16:09

2 Answers 2

22

Never underestimate the value in forcing a user to scroll past something.

Great! Now that you've scrolled past that, let me tell you why.

If there is a better way to get the asker's task done (like in the XY problem) then list that way first, and they start becoming a better programmer by using it. If they deem it unsatisfactory, then the real problem with their code is below it in a footnote. In contrast, if the real problem is first, then all that they'll pay attention to is that, and they wouldn't understand the more elegant solution.

In fact, this is actually the logic behind sorting answers by votes. The asker gets the answer that the community thinks is the best listed first, and if they don't like it, then they can scroll further down and find other answers that might also work and accept one of those.

3
  • 1
    Nice explanation. Also, perfectly syncs with what I believe. Nov 21, 2016 at 14:20
  • 3
    Counter-example: the first answer displayed is the one accepted, even when other answers have a much higher vote count. I wish the higher voted answer was always displayed first no matter which the OP accepted... Nov 24, 2016 at 10:25
  • @MatthieuM. that is an option which other can achieve using filter by votes though it's a good thing but not always , there are some post which has accepted concise answer along with highly voted completely descriptive answer which sometimes given at the link provided in accepted answer so simply this has cons and pros too alternate is use the filter simply Nov 24, 2016 at 11:07
8

The correct way is usually by not answering them since Syntactical and Logical questions like the one linked are usually also localized. They don't generalize well and usually serve only to help the OP with their issue.

That's why questions like these are usually strong candidates for the typo close vote.

Since they usually get answered though (I've done that too), it's a good idea to take into consideration any possible future users (even one poor soul!) by adding a "standard" way of performing it if no other answer highlights this. How you organize the answer -- OP Error first, standard way second or vice-versa -- is clearly personal opinion:

  • Some users who visit this site might like to read the full answer, so how you organize makes no difference.
  • Others might only skim through the question body and if they don't see similarities with their own issue just leave. How you organize it again makes no difference.
  • Others might only look at the beginning of answers and if they don't get satisfied ignore the rest of the answer.

In the end, it is a good idea to include a better way to deal with a problem and do that in a nice organized fashion. Just don't stress too much over it, though.

1
  • 1
    This is the correct approach. The linked question is very localized and of no interest for future readers. The mistake is on such a fundamental level that I suspect that the OP is not a professional or enthusiast programmer, but just some random person who have yet to learn programming: thus this is the wrong site for them, as per site scope. There are already thousands of array-out-of-bounds questions out there, so it can either be closed as simple typo or as a duplicate. The bottom line is: there is zero value in preserving crap questions like these, let alone to answer them over and over.
    – Lundin
    Nov 24, 2016 at 9:00

You must log in to answer this question.

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