I’ve seen this posted in countless forms by countless people having countless issues. It’s sad: more often than not these are good people trying to learn, trying to fix their mistakes, or just trying to get their project working! But many forums and websites shut these people out because they “don’t know how to ask a question” or something along those lines.
Here are the unwritten rules of what you should try before you ask for help.
What is broken?
This is one of the most overlooked steps, and one of the easiest. It’s easy to say “this code doesn’t work,” but that doesn’t help anyone trying to solve your problem when “this code” is five hundred lines spread across a dozen files. Define your problem, and this will help everyone.
“My code is broken”
“What is broken?”
“My contact form isn’t working”
“How isn’t it working?”
“When I click the Submit button, the form doesn’t submit”
“What does it do instead of submitting?”
“The button turns gray and the page doesn’t change”
“What is it supposed to do?”
“The page is supposed to go to a confirmation page”
This discussion alone has turned “My code is broken” into “On my contact form, when I click the Submit button, the form doesn’t submit. The button turns gray, but the page doesn’t change into a confirmation page.” This is much more useful.
What have you tried?
It’s hard for people to help you if they don’t know what you’ve tried and what you haven’t. Going through some basic troubleshooting will show them that you’re not helpless and that you’re actually stuck and not just lazy.
Some things to try
- Check your variables
Sometimes what you think is happening isn’t, and what you think is assigned to one value may not be. It’s important to run a sanity check (of the program and yourself) before you throw up your hands in defeat.
If you’re using an IDE that supports debugging, set a breakpoint at the start of the section that’s giving you issues and step through it line by line. This is by far the best way to figure out what’s happening: just watching the code do its thing.
If you aren’t as lucky, there are still options. In most cases you’ll be able to write things to some type of output (a webpage, a file, a console) and you can use that to figure out what is and isn’t assigned at any given moment. - Make sure you’re seeing all the flags
It’s really easy to miss the obvious if error messages are turned off. Make sure your loggers are set to show all messages (if you don’t know how to do that, search for “<language name> show all errors” and I’m sure someone has asked about it before). You may need to enable a debug mode of some kind, depending on the language and tools you’re using. - Strip it back a bit
Many question sites want a minimal example, and this is for a good reason; if you strip your problem back as far as you can while having it still fail, you’ve eliminated a lot of chances for red herrings and made the issue a lot more clear for someone on the outside looking in.
For instance, if your code checks the date and sends a message to users with a “z” in their name if the day of the week is Wednesday and their last post mentions a fruit, stripping this back could help determine which of these steps is actually causing the issue.
It’s all been done
A big plus to the Internet being the all-encompassing knowledge-sphere that it is is that, in all likelihood, the issue you’re having has been solved by somebody before. It’s mostly about knowing what to search for.
Some good starting points are:
- Error messages
These are really useful, especially if they’re unique. Try to read the message yourself and figure out what the error is first, but if you’re still having issues try searching for the error name/number and message text. If the error references a method or function, or the error points to a line number with a certain method or function, try adding that to the search along with the language or library name. - How to
If you just want your code to do something simple, like read from a file or split a string into pieces, just search for that (along with the language/framework name)! Maybe your solution was wrong or flawed. Keep in mind though that not everyone on the Internet is right, so don’t just read the first answer you see and think that’s the canonical way to do something, especially if it’s an older answer (remember, standards change!) - Read the docs
Documentation is a blessing if it’s well-written, and a byzantine nightmare if not. Roll the dice: most major languages and frameworks do a pretty good job of explaining themselves, and those that haven’t frequently have a myriad of websites picking up the slack. Search for your language or framework and the method/function/class/tool you’re using and most likely you’ll get a tutorial or at least an explanation of how it’s supposed to work.
As an aside, many IDEs have documentation build in, allowing you to use a shortcut or right-click on a library definition in your code and immediately see a reference pop up for how it’s supposed to be used. This is indispensable!
If all that fails you, it’s time to ask…
Asking the question
It’s a good idea, before you actually bother anyone with your issue, to write the question to yourself. Sit down and try to figure out exactly what your issue is. This is deeper than the first step (although if you’ve just skipped down here and not done any of the above, you really, really should). You should try to draft a post in the following format:
- Your issue
This should be your sentences from the first step, within the context of your language and/or framework.
“I’m using <framework name> version <framework version> running on <language name> version <language version>. When I do <thing that triggers the issue>, I want it to <expected outcome>. Instead, I get <actual result>. - What you have tried
This should be a summary of your work in the second step, with any leads gained from the third step. Hopefully those should have honed your issue in on one or two components or functions.
“Debugging the program pointed me to an issue with <some method> in <some library function>, which is throwing this error: <some error>. The documentation says I’m using this function correctly, yet my output is wrong: it should be <expected output>, but I’m getting <actual output>!” - Minimal example
This is essentially the third part of the second step. You want to provide something that people can run and experience the same error you’re getting.
After you’ve written this up, look it over as if you found this post and were going to try to answer it. Does it have all the information you would need?
Another thing to look for are key phrases. When you wrote this out to explain it to someone, you may have described it differently than how you searched for it earlier. See if anything you’ve written is worthy of searching for.
When all else fails
Post it. Send it to a friend, a forum you trust, or a Q&A site. Some of these sites even pull out keywords from your question and try to suggest similar questions, which might solve your problem or give you more ideas of what to search for.
You’ve written a well-formed question. If nobody wants to answer it, it’s not your fault at this point. Hopefully someone will come along and help you out, or perhaps someone else with the same issue will come along and comment as much.
Regardless, you’re much better off now than you were before!