How to Write the Perfect Stack Overflow Question (After Analyzing 10,000)
Join the DZone community and get the full member experience.Join For Free
how to phrase a question in stack overflow in order to get better answers
stack overflow offers a great interface for accessing all of its data and running any possible query in the questions/answers database. we started using this database to better understand the most common questions about debugging (what we’re trying to solve at takipi ). while learning about debugging through thousands of questions, we also noted an additional bonus: we started better understanding what drives the stack overflow community.
this article is the result of researching over 10,000 stack overflow questions. it summarizes how you need to phrase and write your question in order to get better and faster answers. when we started running our scripts on the queries’ answers we weren’t sure we’d arrive at strong conclusions. after looking into a few hundred questions, though, we already started recognizing certain distinct patterns that we were seeing over and over again across different programming languages and topics.
you can find a detailed explanation of how we performed the test at the end of the article, but let’s get to the best part first — the results. the main criteria we set for a ‘good’ question were getting high quality answers (from users with high reputation + votes), getting an answer relatively quickly and the number of votes and views.
keep it short
probably the strongest pattern we saw across all the different queries and scripts we ran was this: the shorter the question, the more likely you are to get a quick and useful answer. the average length of a ‘good’ question was around 1200 characters (~3-4 short paragraphs), while the average length of a standard question was 1800 characters. the strongest effect of the length was on the view count and votes, where the average length of the top questions was around 50% of that of standard questions.
there’s no such thing as too short, either — really short questions (around 200-300 characters) received the best results.
title length matters less, we discovered. while we saw the effect of the question’s length across the board, it seems like the length of the title has a minor influence on the quality of the question. the average title length of the top questions was about 5% shorter than that of standard titles (47 characters vs. 50).
#1 influencer – asker reputation
the asker’s reputation has a huge effect on the number and quality of the answers and the speed of reply. it seems that users with high reputations tend to answer more frequently to users with high reputations as well. while we saw that short questions are 50-100% more likely to get better and faster answers, a question asked by a user with a very high reputation is three times more likely to get better answers than a question asked by a user with a low reputation. you might conclude, of course, that users with high reputations ask better questions. it’s definitely true, but we saw some very similar questions asked by users with low and high reputations, and the difference in the quality of the answer was clear.
some examples: the average asker reputation of the top 100 java questions with the best answers (high reputation of the user who gave the answer + votes) was 4500 points. the average asker reputation of standard java questions was 1500.
the average asker reputation of ruby questions that were answered within 15 minutes was 2400. the average asker reputation of ruby questions that were answered after 24 hours was 1300.
the average asker reputation of the 100 top viewed java questions is 3150, compared to average standard question reputation of 1100.
should i use code snippets?
embedding code snippets in the question was one of the few parameters we tested that gave very clear results across different languages, but opposite results across different criteria. it seems like questions which include code snippets get better answers — answers with more votes and from users with higher reputation. for example, 87% of the python related questions answered by users with a very high reputation included code snippets. 64% of the average python questions include code snippets. ruby-related questions showed similar results — 91% of the top questions included code snippets compared to an average of 79%.
when it comes to votes, views and time until the first answer, the trend is opposite — for example, 58% of the most viewed python questions included code snippets. 72% of the questions with an average number of views included code snippets. it seems like it’s related to the question’s length — code snippets lead to longer questions which get lower results.
use fewer tags
not a huge difference, but it seems that across the different criteria we tested, the top results have fewer tags than the average. questions which got high quality answers, quicker response and more votes had an average of 3 tags (seems to be the same in different languages). standard questions had around 3.5 – 3.7 tags.
when is the best time to post a question?
from our data it doesn’t seem that the time of day affects the results. stack overflow “rush hour” is usually between 11 am and 5 pm utc. about 50% of the questions are asked in that time frame. questions asked in these hours were a bit more likely to get an answer faster (by about 5-10%) but the answers weren’t higher in quality. the time the question was posted doesn’t affect other criteria like votes, views or number of answers.
how to title your question - getting into the
science of wording
use the name of the language/ topic in the title
one of the main scripts we used was built in order to count and analyze the titles. we grouped words according to programming terms (like “string”, “array”, “function”), language/topic (like ruby, mysql, c#), negative/positive words (like “can’t”, “worst”, “best”, “fail”) and more. the most distinct conclusion — if you want to get faster and better answers, use the topic you’re asking about in the title. have a question about something in python? just add python to the title.
some examples: 36% of ruby-related questions that were answered within 15 minutes included the word “ruby” in the title. only 15% of the questions that were answered after 24 hours had the word “ruby” in the title. 58% of the java questions with the highest view count include the word “java.” 39% of standard java questions included the word “java.”
and what about using two languages in the title? for example, “why are string comparisons (compareto) faster in java than in c#?”. it seems like using two different languages/ topics in the title might reduce the number and quality of the answers, as there are fewer users who are proficient in both. however, this kind of questions performed very well and were much more likely to get good results.
it doesn’t matter if you phrase the title as a question or not
here’s one statistic that surprised me. phrasing the title as a question doesn’t affect the speed or quality of the answers.
for example – “add the same method to multiple classes” vs. “how to add the same method to multiple classes?” will gain the same results. the only difference we noted in the research was that titles phrased as questions are a bit more likely to get a faster answer (by about 10%).
something doesn’t work for you? you can’t solve a problem? the community is here to help
a title that indicates that something is not working, or asking about an error, will usually get a better and faster response.
rspec stub doesn’t work
why is bundler unable to reach http://rubygems.org?
can’t import my own modules in python
it seems like using words that indicate failure (“cannot”, “unable”, “fails”, “error”, “not working”, etc.) lead to better answers. for example, 22% of the top ruby questions included a negative phrase in the title, while the average for standard questions was 14%.
however, it seems that indicating that something doesn’t work or asking about an error doesn’t attract users with high reputations. these questions got faster results, more answers, and higher view count, but were answered by users with a less than average reputation.
should i use x or y?
comparing different technologies or methodologies is a good recipe for high quality answers. this type of questions had a significant part in every ‘top questions’ list we formed.
here are a few examples:
why shouldn’t i use pypy over cpython if pypy is 6.3 times faster?
why is char preferred over string for passwords?
why are string comparisons (compareto) faster in java than in c#?
let’s make it interesting
pretty obvious, but many of the top ranked questions point to mysterious behavior or unexpected results.
here are some examples of top questions:
why is processing a sorted array faster than an unsorted array? (6960 votes)
why does changing 0.1f to 0 slow down performance by 10x? (774 votes)
why does parseint(1/0, 19) return 18? (632 votes)
how did we perform the test?
we decided to focus only on questions asked since 2011.
we ran eight different queries and sorted the questions according to: votes, number of answers, favorites count, time until the first answer, time of day the question was posted, questions answered by users with a high reputation, questions asked by users with high reputation, view count. then we compared the top 300 questions in each section to 300 questions that received an average score on the parameter we focused on. this is obviously not an exact science, and there’s not a “scientific recipe” for getting great answers. however, all the patterns mentioned above repeated themselves across the different parameters and different languages we questioned.
here are some of the queries we used: have fun with it and let us know if you find other interesting results.
thanks to dror cohen from codersclan for helping out and to john woo who justified his 120k+ so reputation points and helped us write the queries.
Opinions expressed by DZone contributors are their own.
How Agile Works at Tesla [Video]
RAML vs. OAS: Which Is the Best API Specification for Your Project?
Five Java Books Beginners and Professionals Should Read
How To Manage Vulnerabilities in Modern Cloud-Native Applications