How to ask a good Stack Overflow question.

Before I dive into my own opinions about how to ask a good question, it’s probably important to note that Stack Overflow has provided a guide on this exact topic.  I can think of no better starting point than here.  If you think the Stack Exchange community is full of elitists and you’re mad because your questions are downvoted or closed, then I must implore you to, if nothing else, read that guide.


I previously wrote an entry about how to communicate programming problems to other developers.  It was inspired by the plethora of low quality questions asked on Stack Overflow which offer no details about the actual problem, but the advice should apply in general to any programmer who is about to seek debugging help from any other programmer.

That post does serve as some good advice on how to avoid asking a bad question, but it really only deals with a particularly category of bad Stack Overflow questions: the kind seeking debugging help.  There’s a whole different category of bad questions, however.  The kind that is typically closed on Stack Overflow either because the question is too broad or because the question is primarily opinion based.

Here’s the actual text of one such question (which has since been deleted):

In my swift iOS project:

  1.  I am creating a complex dictionary (nested dictionaries and about 150,000 entries) while I run it in simulator.
  2.  Once this large dictionary has been completely built, I want to save it as a stand-alone file on my mac.
  3. Then I want to manually take that file and add/embed it to another iOS project which can at run-time parse it and use its content as needed.

I am looking for the correct approach to go about this. I researched this and there is a lot of discussion about saving as PList file. Is that the best way to go about it or there is a better way to save a dictionary as a file?

It’s not that this is necessarily a bad question to ask in general.  The problem is that this question does not fit the Stack Overflow format.

The only good way to answer this question, the way it is asked, is with a very, very big blog entry addressing all of the possible options for persisting data on iOS (and note that this question doesn’t even necessarily make it clear that the data should be persisted locally versus server storage in some way).  And that blog entry would also have to address all the pros and cons of all options.  At the end of the day, the user who asked this question still may not know which option to pick, because they’re only slightly better off.  They’ve got an enumeration of the pros and cons of the different options.  But because it was never included in the question, I can only assume that the asker never bothered to think about what sort of criteria the solution needs to meet.  And that’s the first part of why this question isn’t a fit for Stack Overflow: it is primarily opinion based.  Without a specific set of criteria to determine what counts as “better”, how can the question of “what is better?” be anything but opinion.

  • Solution 1 is better because it uses the least disk storage space.
  • Solution 2 is better than Solution 1 because it persists locally without relying on a network connection.
  • Solution 3 is better because despite using more disk space than Solution 2, it serializes the data quicker.
  • Solution 4 is also better than solution 2 because is deserializes the data quicker.
  • Solution 5 is the best of all of the solutions because despite using the most disk space, most RAM, most time, it is the easiest to implement and easiest to understand.

By what criteria do we actually determine “best” or “better”?  In this example scenario, is network access something we care about?  Readability and ease of implementation should always be things we care about, but do the performance drawbacks of the most readable/easiest to use solution rule it out?  In some cases, it definitely will.

Even if we sort out the opinion-based problem this question has, we’ve still got issues.  This question is not specific enough.  Even with well-defined criteria for what the solution should meet, the answer will largely be very dependent on the actual data and the structure of the data (and whether or not the data is even in the best structure at all in the first place, especially when we consider that in this scenario, we are in control of the format of the data).

But perhaps worst of all, with a well defined set of criteria for a solution to meet, the asker could just implement whatever solution(s) they think of and determine whether or not they meet the predefined criteria.  If they do, you’re done.  If not, we’ve got the iterative process to assist us.

So with all this in mind, I’ve come up with a fairly simple step-by-step guide to help prevent anyone from asking this sort of bad question.

  1. Define your criteria.
    This is the most important step.  We will refer back to the criteria defined here throughout this process.  This is how we determine which approaches (if any) count as working.  Your criteria should be specific and it should be written down somewhere so you can refer to it later.
  2. Research.
    If you already have an idea of where to start, you could possibly skip this step, but before you write any code, you have to at least have a clue as to where to start.
  3. Implement a solution.
    You should start by implementing whatever solution is your best-guess at working.  It may or may not be what works in the end, but it will be something, at minimum, a stepping stone toward whatever solution makes it into production.
  4. Determine if your solution meets your criteria.
    Do not worry about if your solution is best.  In most cases, best simply does not matter.  Any time spent finding the best solution after you’ve found a solution that meets your criteria is time spent not solving other problems.  If you are feeling the urge to continue to improve your solution or find other, better solutions then you did not spend enough time defining your criteria in step one.  If you find a solution that meets the criteria but you don’t find that solution acceptable, then you did not adequately define your criteria.  If you found a solution that meets your criteria, you are done and need not continue to the other steps.
  5. Exhaust all possible solutions.
    If the first solution did not meet the criteria defined in step one, try another.  Repeat steps three through four until you find a solution that works or until you have exhausted all possible solutions.  Come up with a reasonable amount of time to spend on this iterative process.  You must find a happy balance that gives you enough time to give yourself a chance to resolve the issue without spinning your wheels to long getting yourself frustrated.  For me, before I reach out to Stack Overflow with a question, I have been stuck on a problem for a minimum of 72 hours.
  6. Adjust your criteria.
    If you have spent a reasonable amount of time exhausting all possible solutions and find that none of them meet your original criteria, reconsider your criteria.  Consider if there are any aspects of it that could be loosened even slightly.  If so, go back through the iterative process of steps two through five and determine if any of these previous solutions meet the new loosened criteria.  This should be relatively quick, because you should already have all of the data from lots of iteration over steps two through four while you were stuck on step five.
  7. Reach out for help.  Don’t forget to share your findings so far.
    If you have exhausted all possible solutions and loosened your criteria as much as possible, and still have not found a solution, it is now time to reach out for help.  That doesn’t necessarily mean it’s time to immediately post a question online.  You should strive to build up a network of fellow coders to seek advise from, and start with them during this step.  But if all else fails, then by this point, you’re prepared to ask a question on Stack Overflow.

And by the time you reach the point of asking a question, if you’ve followed this guide line, your question should be absolutely excellent.  You’ve got a well-defined set of criteria.  You’ve got exhaustive research demonstrating the solutions you’ve tried, and if you’ve read this post then you know how to effectively communicate why all of the solutions you’ve tried so far aren’t working for you.  Your question should be in no danger of being closed.  It’s going to be a good question at this point, and good questions only get closed if they are duplicates.  But because you did your research in step two, you know that your question isn’t a duplicate question, right?

Leave a Reply