How to Answer Questions on Stack Overflow
- 4 minutes read - 644 wordsI enjoy answering questions on Stack Overflow.com. It helps me learn about common challenges and practice reviewing code. In the beginning, it also unlocked basic site features like voting.1
Maybe you’d like to answer questions too! In this post, I’ll explain how I answer questions on Stack Overflow.
I answer questions by:
- Finding the Question
- Gathering Information
- Answering Quickly
- Making Comments Obsolete
💡 As a working example, here’s an accepted answer of mine: ‘Converting React files to Typescript’. I’ll be referencing it throughout.
Find the Question
You can’t answer the question until you know what the question is. That can be harder to identify than you might think!
XY Problems, or questions about a proposed solution rather than the problem, are common on Stack Overflow. Empathetic askers want to help the people who are helping them by offering a solution. But often, the solution is wrong.
It takes experience to spot these kinds of questions. They usually start with an unusual request, like: “How do I force a failing test to pass on CI?” Leave comments asking questions until you arrive at the actual question.
💡 The question I answered was titled “Converting React files to Typescript.”
After some prodding, it ended up something more like “Why is products.find
not a function?”
Gather Information
Stack Overflow loves a minimal, reproducible example (reprex). I’ve learned that questions are rarely close to this ideal. If the asker had that kind of debugging instinct, they would likely not be stuck. Ask for edits to make things more clear.
I enjoy messy questions. They give me time because the needle is deeper in the haystack.
For frontend questions, I recommend Code Sandbox. Type ‘react.new’ into a browser bar, and you’ll be redirected to an online text editor and running React application, ready to go. Paste the question’s code and start deleting until you have reprex. Sometimes I don’t find one, and then I can share that information with the asker.
For languages, I use a REPL. For server-rendered frameworks I often hack on the many abandonware projects on my computer.
It’s just debugging from here. The usual suggestions apply.
💡 In my answer, reading the code showed me that products
was being passed as
an object, but a function was being called on it, .find
, that does not exist on
JavaScript objects.
Answer Quickly
Once I get an answer, I post a hasty version. Then, I take about five minutes to add code blocks, links, and check spelling and grammar. The first correct answer gets attention, so being first, and correct, is desirable.
💡 In my answer, I iterated on my answer first as a comment. Submitting the comment, seeing positive feedback from the asker, and answering a second question in the comments, told me I was on the right track.
Make Comments Obsolete
The last thing I do, I call ‘making comments obsolete’. If your answer is correct or close to correct, you’ll get feedback. An example would be: “Why not use fetch?” When I agree with the feedback, I edit my post so the code is better. When I don’t agree, I can challenge the argument. Don’t ignore the feedback!
Conclusion
What about asking questions? I’ve never asked a question on Stack Overflow. I’ve noticed that typing out my question in the text area helps me see why it’s a bad question full of assumptions and shaky logic. I bet this happens a lot.
Enjoy Stack Overflow; learn, help people, and earn rep! I’m Jake Worth on the site. I’d love to hear your tips and tricks for being a good Stack Overflow citizen.
-
I’m always logged into SO, and I always vote on questions and answers that have helped me. So I have a living record on every page I’ve visited and used in the past. I can’t imagine trying to work without this context! ↩︎