DEV Community

loading...

How to Write Better Questions on StackOverflow

mccurcio profile image Matt Curcio ・2 min read

Slipped my mind that I could use my brain,

The Lemonheads, Rudderless

I have been reading over novice StackOverflow (SO) questions on its Review queues. People may not be aware that a newbie's first question and answer are reviewed before being displayed on SO. I wanted to share a few things I have seen.

I. Information Overload:
Many beginners post (sometimes regurgitate) huge error messages and vast code chunks onto the site unprocessed. Then add, "I can't figure it out, what's wrong with it..."

So, your problem is hidden in 500 lines of code or error messages. On StackOverflow, you will probably be asked to pair your code.

Stop, take a breath, then examine the messages slowly. ;)

  • Use the information you have wisely.

If you have 500 lines of code, one tactic is "Divide and Conquer." Why does that sound familiar? Simplify your code or error messages. In my judgment, you can use either Addition or Subtraction.

Build-Up your problem code. Start from a known reliable point, then add one line (one grouping or one function) at a time. Make your function do one small task before adding sophistication.

Conversely, Break-down the code, line by line. Subtract lines, groups, or functions that don't serve the functionality you attempt to produce. Is your issue in that section? Treat it like an experiment.

Ask yourself this, 'which is better to show my co-worker 500 lines or 10-15 lines with a problem in it.'

II. Read the Docs or Manual:
Others go to SO immediately and ask without a thought.

Stop, take a beat, and think.

StackOverflow reviewers do not take kindly to those who do not give the problem a little research first. Find the book or manual. I like reaching for a book when possible. Getting a book reminds me of when I was 12 and told Get the DICTIONARY. The act of thumbing through the pages gave me a moment to breathe and slowly think about the word and its spelling.

  • Use your Resources wisely!

III. Show Reproducible code:
This last one can be tough BUT very important. SO is for asking specific questions about code. Don't waste 100 words describing your problem when you can show the code. Show your code with some example data! StackOverflow LOVES this! Tell your colleagues what you want the code to do and show them where it goes wrong by adding the inputs that count. Give reviewers something concrete to work with and help you. Without a real example, it is just a debate not help.

I get it. People get overwhelmed, and their brains turn off. I'm sure you know that neuroscience has determined that your prefrontal cortex shuts down when you become anxious. The prefrontal cortex deals with problem-solving and decision making, and if that gets short-circuited, you need to slow down.

Discussion (0)

pic
Editor guide