Photo by Timothy Dykes on Unsplash

Debugging WTF

Thu Feb 25 2021

Debugging can often be one of the biggest four-letter words in software development. But it shouldn’t be. For one, debugging happens. Every project ever coded will need to be debugged, because every project ever coded will mess up in some way or another, at least once (usually multiple times). Also, debugging teaches you more about how your code actually works than all the tutorials and classes put together. For that reason, here are some tips to help make debugging a little smoother and hopefully more fun.

  1. READ every error message. Don’t just skim it, or say, “I have an error” then immediately ask for help or drop your code. Most error messages have a huge amount of information for you, and many are fairly straightforward. Sometimes they tell you exactly where in your code the issue lies. If not, then they usually tell you at least the ballpark area where your code failed, allowing you to zero in on it from there.

  2. Read the full stack trace. You may not want to do this every time, but at least every so often, you should read the full stack trace beginning to end. This helps you figure out the order in which the various pieces of your code are running, and the dependencies within that flow. Keep in mind that the actual failure point (your error) may be at either the top OR the bottom of the trace, depending on the language/framework you are using.

  3. Try to see if you can solve the issue by yourself before googling the answer or reaching out for help. Most people learn far more from their own mistakes than any other training experience. You’re a better coder than you think. If you understood the information #1 and #2 gave you even a little bit, then you probably have at least an idea of where to look to fix your code. Start there. Master Google-Fu. Whatever your favorite search engine, it is your best friend. If you can’t figure it out on your own, start searching for answers by copy/pasting the error message (just the error message, discerned in #1 above — don’t paste the entire stack). If you're fortunate, you may get results that exactly match your situation. Most likely, you will need to read posts and articles that kind of match what you’re facing, sometimes many of them. The more you understand what your code SHOULD be doing and what it is ACTUALLY doing, the more you can filter out the information that doesn’t apply and apply that which does.

  4. Ask. For. Help! This is not weakness or some symbol of failure as a developer/person/self-sufficient living organism. Identify the person or group of people most accessible to you who are most likely to answer the questions you have, explain your situation (politely and without complaining), and ask for insight. Then be open to the answers you receive. You may not like those answers. You may be told to completely rewrite your entire codebase. Accept it with a grain of salt, be gracious in your thanks, and again filter out the information that does not actually apply to your unique issue.

  5. Rinse and repeat. Continue cycling through steps 1–3 until you find the answers you are looking for. Don’t spend too much time on any one step. If you stop making progress on one step, move on to the next, or start the process over, somewhat differently. Search for different but related terms, ask different people, reread your code, etc. Go back to when your code worked (version control like Git makes this much simpler) and trace through it manually until you find what went wrong.

  6. Manage your emotions. Don’t snap at people trying to help you, even if they are completely wrong. Don’t berate yourself. You know what you are doing, and troubleshooting is a natural part of coding that all developers face. And if you get frustrated, walk away for a while. Go watch a movie, take a shower or a walk, play a game, something. Anything that is not actively looking at the problem. You’ll be amazed how often that will be the moment the solution comes to you.

The most important thing about debugging is your attitude. See the issue as a challenge that you will overcome, and that is exactly what you will do.

Happy coding!