Things to keep in mind for debugging

Jake jonggu baek
3 min readMar 16, 2021

--

I would like to share what I learned from Ana at Juno College, which is what developers keep in mind when writing code and debugging.

  • Prevention is better than fixing. Write small pieces of code and test them. If you are using a new library, function, etc., test it separately before adding it to your code. Create tests for each part of your code, so it is always working. Do not write large amounts of code and hope they will behave. They will not, and you will have a lot of places to look for a bug.
  • Try to create a mental model of what may cause the bug before reviewing your code. Logical bugs are not based on what is written but how the problem is solved. Have a plan on what you will test, what the expected results are, and what to do with the information you gather. Don’t forget to test for negative scenarios too (create tests that show what should happen when something goes wrong, not only what you want to happen).
  • Read the errors/warnings. This may seem obvious, but believe what the messages say. Eventually, errors/warnings may point to the wrong line or error, but in the majority of cases, they point in the right direction. Do not ignore them.
  • Typos and letter omissions are the most common mistakes. Don’t look for complex explanations. Look for typo errors first.
  • Do not change the problem/approach/solution when you encounter unexpected behavior. If you are basing your solution on something that worked before (in someone’s code or yours), look for the bug and fixing it is better than trying something else. Constantly changing your approach/solution will result in frustration and a lot of lost time. If it is a new approach, test it in a simpler example first.
  • Console.log or use a debugger to check each step of your process.
  • Explain it to someone, even if it is a ‘rubber duck.’ A fresh pair of eyes on your code helps you see errors that you got used to.
  • Do not change your code in major ways trying to tackle a bug. Removing/commenting out large pieces of code can create other issues that will make the process much harder. If it is absolutely necessary, encapsulate things in functions and just don’t call them.
  • If you are getting warnings or errors in a part that seems unrelated to the bug, fix them before moving on. They may be impacting your code in unexpected ways.
  • Be constantly critical of your code. ‘It was working before’ or ‘I am sure that part is correct’ will not help you solve bugs. Always keep track of what changed and look for errors there, but also keep in mind that things that were working can be broken now because of changes in other parts of your code.

Remember, debugging code is more mentally demanding than writing code. The longer you try to track down a bug without success, the less perspective you tend to have. Realize when you have lost perspective on your code for debugging. Take a break, ask for help, or just let it rest for a day.”

These changes improve the readability and clarity of your valuable advice on debugging and coding practices.

-Ana Rodrigues from Juno College

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Jake jonggu baek
Jake jonggu baek

No responses yet

Write a response