Debugging: Door to new learnings

Debugging: Door to new learnings

Don't give up, embrace this process.

Hello, world! I’m Nitin Singh an undergrad student and app developer. I’m thrilled to publish my first-ever blog on Hashnode as a part of #debuggingfeb.

Debugging is a critical part of the software development process, and yet it's often seen as a frustrating and time-consuming chore. But what if I told you that debugging can be a gateway to new insights and discoveries and that by embracing this process, you can unlock a whole new world of learning and growth?

In this blog post, I’ll be sharing my experience with debugging and how it helped me become a better developer over time. If you are a beginner just starting out on your coding journey and looking to improve your debugging skills, do read the blog. I hope my insights and tips will help you approach this process with confidence and excitement and look at it as a door to new learnings rather than an obstacle.

So, let’s dive in, and discover the power of debugging together.

Introduction

Before starting let's see what does debugging mean?

It is a process of finding and fixing errors, bugs, or issues in code.

When I started to learn to build apps, I got a bunch of errors in the path and as a beginner not able to resolve problems, things like “I’m not good enough always used to cross my mind.” Debugging seemed like an insurmountable obstacle - a never-ending cycle of trial and error, frustration, and confusion.

But over time, I’ve come to realize that debugging is not evil, but a powerful tool for learning and growth. By taking a step back and examining the code from different angles rather than getting hyper, I’ve been able to identify hidden bugs and opened my door to new learnings.

By approaching the process of debugging with a mindset of curiosity, experimentation, and problem-solving, we can unlock new insights and discoveries, and gain a deeper understanding of the inner workings of our code.

Now, let’s see how I use this same approach to perform debugging with an example.

My recent win over an exception as a learner

I would like to share one of my recent debugging journeys. A few days back when I was learning Bloc (Business Login Component), a state management design pattern that is used in the development of Flutter Apps, everything was going well, I was creating a simple app in which the app would show data fetched from local host to my android emulator on the press of a button. When I clicked on the button, I got an error that I was unaware of. Despite following each step very carefully as shown in the tutorial, I got this error. As I mentioned above “don’t look at the error as an obstacle but as a door to new learnings.”

Looking at the error, I knew that there is some problem with fetching data. So, I used some print() statements to find out where exactly the problem is and found out that fetchData() function has some problems. I immediately copied the error and searched on google to know about it.

After going through Stack Overflow, I got to know that the problem is that I’m making a request to a local host from my emulator, but my emulator doesn’t know about the local host. So, I tried to resolve the error with the solutions provided on the stack overflow, but nothing worked.

That whole day went in the search of a solution with nothing in hand.

I was aware of the problem but none of the provided solutions worked for me. And at the evening after trying out all the solutions and some tweaking, what worked for me is -

➡ Change host name part of the URL variable to ‘10.0.0.2‘ as AVD uses it as the special alias to your host loopback interface (aka 127.0.0.1).

➡ Also, manually set the proxy of the emulator. Click on the more button on the sidebar of the emulator.

➡ Go to the settings.

➡ Set the Host name to 10.0.0.2 and the port number to the port no. of your local host and apply it.

➡ And voila the app was running as expectedly.

How to deal with errors?

Dealing with errors becomes easy when you divide the process into steps. Whenever you get an error, simply ask these three questions.

Where is the problem?

  • It helps to narrow down the scope of the issue and identify the specific part of the code that needs to be examined.

  • Use print() statements to find where the code is breaking.

What’s the problem and cause?

  • It helps to understand the underlying issue and its root cause. This can help in determining the appropriate solution.
  • It might be a small mistake like, a syntax error, typos, etc., that is not letting your program run.
  • If you don’t know about the error, copy it and search on google. Go through web pages and learn more about the root cause of the problem.

How to solve it?

  • It helps to identify potential solutions to the problem and implement them to fix the issue.
  • Check out the documentation for troubleshooting guides, and solutions to common problems.

  • Ask your peers for help or use social media platforms.

  • Use debugging tools.

  • Use AI tools like ChatGPT.

Conclusion

As a developer, everyone has to go through the phase of debugging, it can be as a learner or a seasoned developer. Rather than seeing an issue in the code as an obstacle, look at it as a door to new learnings, I have followed this, and it really helps. If you're struggling with debugging, don't give up - instead, embrace this process as an opportunity to learn and grow.

Connect with me via Twitter, LinkedIn, GitHub

If you liked reading this blog, please don't forget to like ❤️, comment 👌🏻 and share 🤩