10 Tips for Debugging Code

  • Published: Monday, Sept. 14, 2020

Troubleshooting, or debugging, code can be frustrating and tedious. It is one of the biggest things that turns most students (and teachers) off of coding. These 10 tips are intended to help teachers not only teach debugging techniques but also give them some best practices for helping create good debuggers.

  1. Start with a plan: Know what you want the code to do before you start coding. Coding on the fly is a bad plan.
  2. Break the code into chunks: For example, step one for a game would be set the background, then generate the characters, then character movement, interaction, scoring, etc. Get each chunk working the way you want it before you move on.
  3. For syntax-based coding (hard coding), start simple: Using a JavaScript example, check for semicolons at the end of code elements, then spaces, then quotes and commas, etc.
  4. Test often: Run your program after each new element is added.
  5. Make one change at a time: If you have a problem with your code, make ONE CHANGE AT A TIME and then test. Don’t make several changes at a time. If you make more than one change, how will you know which one worked (or didn’t)?
  6. Use comments: Not only to document everything you are doing (so it makes sense later), but if something stops working, comment it out while you work on it so it doesn’t stop you cold.
  7. Check your variable names: The more you use them, the easier it is to mix them up.
  8. Use Google: There is NO original code anymore. Whatever you are trying to do, someone has probably already done it. See if you can find a similar code block to model.
  9. Speaking of Google, use forums: There is always someone willing to help, especially with educational code sites like Edublocks or Scratch, Code.org, etc.
  10. Step away from the code: We can’t tell you how many times just getting up and taking a break has made the mistake just pop off the page when we get back!