How to Find a Bug in Your Code | 8th Light (2024)

So you’ve got a bug in your code? How in the world do you find the thing? Here are some of the techniques I use to identify the offending code.

Bisect differences

Was the bug introduced fairly recently? If so, you can jump back in the code to a time when the bug was known not to exist. Using the git bisect command, you can perform a binary search through your code base until you find the commit where the bug was introduced. Looking at that diff should give you a fairly small amount of code to dig through. This is a fantastic technique when you are working in a new or unfamiliar code base.

Explain the problem to a teammate

Speaking is thinking. Oftentimes, just forming the words to describe the bug to a teammate will lead you right to the source of the problem. A good colleague will ask you probing questions to help you think about the problem in a new way.

Signal Processing

I began my career programming signal processing microprocessors in assembly. (Fun, right?) In any assembly language it can be pretty hard to keep track of what was what (no named variables!). In signal processing, you get a data sample for a time period, transform it with a pipeline of algorithms, and pop out an output sample. When I would need to find a problem in a calculation, I had to step through the code, instruction by instruction, verifying the intermediate results in the registers along the way.

All code can be looked at like a signal processing chain. Something happens that then causes something else to happen, and then at some point you are expecting the correct output or side effect. To debug with this method, start at the beginning of your buggy scenario. As a mental exercise (or with a debugger or series of print statements), step through each method, function, or transformation one at a time until you find the problem. Granted, it may take you a long time if your problem is toward the end of your process, but you always know where you have been and where you are going.

Test-Driven Bug Finding

There are a lot of assumptions you have about your code. Hopefully, most things you know are covered by a test; but if you suspect a problem somewhere, try poking at it with a new test. Maybe there is an unconsidered corner case or some unwritten assumption that was violated.

It is easy to fall into the trap of guessing where the problem is, then looking there and not finding anything. Then, you jump over to somewhere else. You do that a couple of times and you have no idea where you’ve been, and you keep looking back at the same thing over and over. Try one of these techniques to keep track of where you've been and help you find the bug.

What more? Check out the rest of this series:

How to Find a Bug in Your Code | 8th Light (2024)
Top Articles
Walmart heir Rob Walton just retired from the retailer's board after 4 decades. He and his 2 siblings are worth a combined $228 billion — more than Jeff Bezos or Elon Musk.
LCM of 20 and 24 | How to Find LCM of 20 and 24
3 Tick Granite Osrs
Dricxzyoki
Mountain Dew Bennington Pontoon
PontiacMadeDDG family: mother, father and siblings
Gabrielle Abbate Obituary
Caroline Cps.powerschool.com
Umn Biology
3656 Curlew St
Revitalising marine ecosystems: D-Shape’s innovative 3D-printed reef restoration solution - StartmeupHK
David Turner Evangelist Net Worth
“In my day, you were butch or you were femme”
Viprow Golf
Diamond Piers Menards
Carson Municipal Code
360 Tabc Answers
Laveen Modern Dentistry And Orthodontics Laveen Village Az
Pecos Valley Sunland Park Menu
Brbl Barber Shop
Engineering Beauties Chapter 1
Bellin Patient Portal
Utexas Iot Wifi
Move Relearner Infinite Fusion
European Wax Center Toms River Reviews
Tinyzonehd
They Cloned Tyrone Showtimes Near Showbiz Cinemas - Kingwood
HP PARTSURFER - spare part search portal
Www Mydocbill Rada
Christmas Days Away
Was heißt AMK? » Bedeutung und Herkunft des Ausdrucks
Where Can I Cash A Huntington National Bank Check
Roch Hodech Nissan 2023
Most popular Indian web series of 2022 (so far) as per IMDb: Rocket Boys, Panchayat, Mai in top 10
Netherforged Lavaproof Boots
Craigslist In Myrtle Beach
Junior / medior handhaver openbare ruimte (BOA) - Gemeente Leiden
Devotion Showtimes Near Mjr Universal Grand Cinema 16
Ljw Obits
Tal 3L Zeus Replacement Lid
Claim loopt uit op pr-drama voor Hohenzollern
Evil Dead Rise (2023) | Film, Trailer, Kritik
Craigslist en Santa Cruz, California: Tu Guía Definitiva para Comprar, Vender e Intercambiar - First Republic Craigslist
Umd Men's Basketball Duluth
Fluffy Jacket Walmart
Wisconsin Volleyball titt*es
Madden 23 Can't Hire Offensive Coordinator
Motorcycle For Sale In Deep East Texas By Owner
Spn 3464 Engine Throttle Actuator 1 Control Command
O.c Craigslist
Secondary Math 2 Module 3 Answers
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 6165

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.