How do I ask a good question?
Stack Overflow depends on volunteers. The better your question, the easier it is for those volunteers to find an answer to your problem.
- Try to solve the problem yourself; search first
- Summarize the problem, including anything useful you found
- Provide the shortest code that reproduces the problem
- Review your question before you post it
- Be an active participant
Search for Solutions
Often asking a new question on Stack Overflow isn't the quickest way to get an answer. Get a cup of coffee, take a walk around the building, and try solving the problem yourself again. If you're still stuck, try using a search engine, checking the official documentation, or searching on Stack Overflow for existing resources that may solve your problem.
Even if you can't solve the problem yourself, looking for an answer will help you understand the problem better, figure out what sort of solutions aren't working for you, and allow you to ask a clearer question.
Summarize the Problem
The first thing people will read is your title. Make sure that it clearly describes the specific problem you're facing. When you were searching in google for a solution, what terms were you using? If the title is clear and defines the problem, more people will be interested in taking a look and trying to solve it.
The beginning of a question should include a brief summary of the problem:
- What are you trying to do?
- What is your desired result?
- What is actually happening?
- What if any relevant information have you gotten from trying to fix it yourself and doing searches?
Provide Code to Reproduce the Problem
After people understand what your problem is, make sure that they have the tools to work on a solution themselves. If you don't include any way for them to troubleshoot the issue, you have a far smaller chance of getting a working answer.
The best way to do that is to provide code to reproduce the problem. Make that code minimal, complete, and tested to allow people to get started finding a solution as quickly as possible. Depending on the language, putting a working example on a site like jsbin or sqlfiddle in addition to the code in the question body will help people find an answer even quicker.
Not everyone can access external sites, the links may break over time, and posting questions which include such links but no code may be prevented by our automated quality filter
Review Your Question
Once you've written your question, take a look at the preview before you hit post. Read it as if it were someone else's problem:
- Is it clear what your problem is?
- Is it clear what you are looking for the solution to do?
- Is it easy to reproduce the same problem with only what's written in the question body?
- Is it formatted nicely?
- Do you notice any spelling or grammar mistakes?
No question is going to be perfect (you can always edit your question later if you find a mistake), but the better it looks when it's first posted, the more people will take a look at it and try to find an answer.
Participate in the Search for a Solution
Sometimes what you think was clear when you posted it isn't clear to the people looking for an answer. After you post the question, you may get comments looking for clarification, or quick answers suggesting solutions. If one person has a question, it's likely that other people will too, so make sure to edit your question to clear up any misunderstandings based on the comments and let people know you are working with them for a solution.
If your question is a particularly difficult one, it may take some time to get an answer. Don't get discouraged! Keep working on the problem yourself. Sometimes you will find the answer while waiting, and can answer your own question to help out people who run in to the same issue in the future.
Resources
Asking good questions is a skill that takes practice to master. If you want to learn more about writing a good question, take a look at these resources: