Debugging

During the COVID-19 pandemic, schools ended early (but students still need to go to lessons online via Zoom). In April, starting this week, I have an Easter Break that lasts for 2 full weeks. Initially, it was meant to be a break so people can go outside and relax, but now everything seems to change. No one could go outside, go on vacations as most countries are in lock-down mode, hangout with friends. So the only option is to stay at home. During the break I continued on my project - Subtle, the Todo App.

Bugs

This morning I was going on Instagram, and I saw a post about Types of people during Quarantine. There are a few that caught my eye, such as the introverts, the freelancers and the heros. But then I thought about programmers/developers.

As a beginner programmer, the ONE THING that ruins my day is BUG(s). They usually come in the color red, with a vague caption on the top that usually reads TypeError: Cannot read proprety ‘xxx’ of undefined. Let me show you how BUGS affect my daily mood. 😁😡

Here is A Day in the Life of a Programmer (beginner version) :

  1. 😁 - I run the code, it runs smoothly 👏(congrats)
  2. 😁 - I start to add new features
  3. 😡 - I run the code again and something red pops up.
  4. 😡 - I google the bug, look at my code and do some corrections
  5. 😡 - Continue Step 5 and 6 over and over again until nothing red shows up, sometimes it might not be an error but the outcome isn’t what I was expecting. On average it takes me 2 hours to debug one singe bug. (Quite time consuming…)
  6. 😑 - If I can’t debug the code, I usually do something else (i.e. Eat lunch, sleep, watch YouTube)
  7. 😁 - Finally, I solved the bug
  8. 😑 - I repeat the steps all over again

As you can see, my mood swings a lot. Quite drastically, from happy to mad, back to happy and back to mad. Often times I get demotivated as the code seems unsolvable. But I found a few tips and tricks to debug my code.

5 Ways to Debug your code

1. Use console.log()

  • In javascript it’s console.log(), in python it’s print.
  • It prints out the value of a variable you’re declaring in the console
  • It is an effective way to check your variables, methods, and function. Making sure they are working perfectly, if not it can also pinpoint the error.

2. Use Google

  • Many programming languages have existed for a decade or longer, many problems you faced were also faced by many people
  • Websites such as Stack Overflow, Github, MDN web docs (if you are using javascript) are great ways to find solutions for your bug

3. Go on Youtube

  • On Youtube, you can find videos that teaches you how to code from scratch
  • You can reference some of their codes to your project

4. Ask a friend

If you are like me who doesn’t have friends that code, use online platforms.

  • Discord, join public servers and ask questions. Many people in the server are more experienced than you.
  • Reddit, post your question on specific categories or just search for similar bugs and see the responses.

5. Sleep

Many times, I take breaks in between just to relax my brain cells (kinda). For me the best thing is just to take a break. Often times I think of alternative ways to solve the bug or even different ways to get the final results.

END

This blog gave you some simple tips and tricks on debugging when you face bugs.

Thanks for reading 👀. There will be a weekly blog every Friday, Stay Tuned.😉