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.
- Start with a plan: Know what you want the code to do before you start coding. Coding on the fly is a bad plan.
- 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.
- Test often: Run your program after each new element is added.
- 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)?
- 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.
- Check your variable names: The more you use them, the easier it is to mix them up.
- 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.
- Speaking of Google, use forums: There is always someone willing to help, especially with educational code sites like Edublocks or Scratch, Code.org, etc.
- 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!