Identifying Muggles in Your Code: Debugging Your Apps Without Spells

As a developer, one of your biggest, ongoing challenges is debugging your code. It’s a lifelong battle fought by all developers both new and experienced. How do you find what went wrong in the mountains of code? The offending code could be anywhere, and you need key ways to identify the problem before it grows.

Personally, I find it helps to compare these bugs to muggles. Like in the wizarding world, you can’t always see the difference from a muggle and a wizard upon first glance. However, a muggle at Hogwarts would make themselves known quick. We need to make sure your bugs in your code stand out like a muggle at Hogwarts. Here are some techniques for identifying your offending code without any fancy spells.

Train With Smoke

Image via Pexels

Bisect Recent Differences

If you know your bug is recent, that makes finding it a little bit easier. Think of this like jumping through time—or using a time turner, if we’re still in the realm of Harry Potter—to find the mistake when it happened. We can do this using the gif bisect command. Then, you’re free to perform a binary search until you find where you introduced new code.

From here, you’ll only have a small code base to sift through. That muggle is closer than you think, and you’ll probably spot it without any headache at all. This is the best strategy for working with new or unfamiliar code where you’re likely to run into frequent problems.

Start at the Beginning

No, I don’t mean scrap your code and start over. I do mean thinking about your code differently. It’s easy to get caught in a mind-loop of frustration when debugging, but this will get you nowhere. You need to perform a type of mental exercise to start at the beginning of your bugging situation.

Step through all method of your code one step at a time. This will be time-consuming, but it’s the most effective way to find a particular problem in your process. Hopefully, your bug is near the beginning of your functions, so it won’t take too long to discover. Either way, you’ll know exactly what works and what doesn’t.

Person Looking at Phone and at Macbook Pro

Image via Pexels

Talk it Out

Don’t underestimate the power of simply talking out the bug with someone. This isn’t a fancy developer tool, but it’s just as effective. Like I said before, it’s easy to get caught up in the stress of the bug. You forget to simply break down the problem into simple, approachable parts.

Talk to a teammate. Describe the bug to them and see if they have any ideas. Most likely, they will. They can ask probing questions to help you determine the source of the problem. Sometimes just describing it out loud is enough to spark some insight.

Debugging Tools

Before you resort to Stack Overflow, try some debugging tools. You’re not in this alone, and that’s why specific bug tests have been created in the first place. There are a number of free or affordable debugging tools every developer should have in his or her arsenal. They’re basically your wand if you’re a wizard. Only, instead of wands which choose the wizard, you’re free to choose your own debugger tool.

  • Chrome Debugging Tool – For verifying values in your browser.
  • Node Inspect Like Chrome Dev Tools but it’s used for server code.
  • Webpack For discovering syntax errors.
  • InstabugFor debugging mobile apps with testing.
Blue Printer Paper

Image via Pexels

App Monitoring and Logging

Finally, to make sure your bug doesn’t come back, set in place some safety features for your app or software. Using an application logging tool like Loggly will not only alert you of any future problems, but it will help you keep track of real-time performance. It’s something no developer should go without in this day and age, no matter the project you’re working on.

Ultimately, debugging apps is always a bit of a pain. It also helps you grow as a developer, whether you solve the problem in a few clicks of a day of work. As you can see above, finding your muggle at Hogwarts is a mixed bag situation. Sometimes it’s simple, and other times it takes more manpower.

Either way, it’s up to you to be up to the challenge if you want your code to work. Unlike wizards, we don’t have any magic spells for solving the problem instantly. This just means we learn how to write stronger code.