How to Debug:

I have been listening to an audiobook The Complete Software Developers Career Guide on my way to work. I highly recommend this book to developers that have long commutes or do daily low intensity cardio and want something valuable to listen to. This book has already reshaped many of my preconceived notions about several aspects of development and I’m only about half way through it.

Backstory:

In April, I began my first job working on a software development team. The project is a few years old, so there is a large codebase that I have to learn and I am working bugs to learn what others have been doing, how the project has been designed, and to sharpen my debugging skills. Debugging is a skill that will serve me for the rest of my career if I can master it. It’s inevitable that all developers will create bugs and having a strategy going in saves time.

The problem:

When I began debugging the project, I would find some value that was incorrect or missing, start up the debugger, and begin searching for the cause. I had been told on a podcast that using a debugger well is the key to debugging! The amount of time varied from a few minutes to a couple of days. When the debugging sessions were long, it became easy to forget what I had tried, which classes I had looked at, and even what the original bug was. Sometimes I ended up finding other bugs along the way, and fixed those, only to realize that I had not made much progress on the original issue. This process becomes mind numbing and I often found that at the end of the day my brain was just foggy and exhausted from the intense session of speculation and skepticism I had just put myself through.

What does John Sonmez have to say about debugging? Use the debugger as a last resort.

What?! How could this be true? I have learned that the debugger is a powerful tool, handed down from the gods of software engineering to break my code apart, and interrogate each variable for its secrets! Why would I not use this all powerful hammer the pound all of the bugs in my code flat into the ground?!

Here are the steps he recommends:

  1. Start by reproducing the bug. If I can’t, I can get a tester to show me how the bug is produced. If I can’t do this, I can’t fix the problem, and I can’t test it.
  • Ok, this is obvious, but don’t lose hope, keep reading.
  1. Try to determine how I think the bug is happening, and think about ways that it could occur (without opening the debugger to check).
  • John calls this the “Sit and Think” step. The idea here is to reduce the scope of the problem. If I can determine a few potential areas where the bug can occur, this will help me prevent the 10 hour debugging sessions where I inevitably look through every piece of code that component touches looking for abnormalities and causing short term confusion and brain fog.
  1. Test hypothesis by writing a unit test(or another kind of test) .
  2. If a test fails on the case, then I can use that to test the problem. When it passes, I can be sure that it is resolved. (Remember that making a test fail is an important step in writing good tests.)
  3. If I write a test, and it passes, then I have a test that tests another piece of functionality.
  4. I now know, that the tests that are passing are not the issue, and can move forward knowing that I have tested those components and they work as intended. This narrows the scope of the problem and helps to break the problem down further as I progress. John uses the analogy of “closing and locking doors” as I traverse the problem.
  5. All of the above scenarios improve the code, and makes it more maintainable. Developers working on this code can now run the tests and check that they didn’t break anything.

Why is this approach better?

Instead of just fixing the current problem, I have eliminated the source of the problem. I also made the code easier to maintain with unit tests.

These are just my own notes, John has much to say about debugging and code maintainability. Check out the audiobook The Complete Software Developers Career Guide Chapter 32 (Chapter 38 if using audible app). John is the founder of simpleprogammer.com and is a pluralsite author sharing tons of valuable programming content online.

2022

Etsy

less than 1 minute read

A process to create products on Etsy

Brain dump 2

1 minute read

Brain dump 1 (old brain dump from 04-2020 with checkboxes filled as of today 01-2020)

Back to top ↑

2021

Back to top ↑

2020

A mini follow up to my habit tracker

2 minute read

Habit tracking part 2: Reiterating my goals for my habit tracker This is a follow up to the first post I made about this topic. I have been using the habit...

How to Debug

3 minute read

How to Debug: I have been listening to an audiobook The Complete Software Developers Career Guide on my way to work. I highly recommend this book to develop...

Back to top ↑

2019

The Magical Manager

2 minute read

The Magical Manager So, who is this guy? When I began working with Jack Zoellner, I was told by my coworkers that Jack was really a great software develope...

Today I started using a habit tracker

4 minute read

Today I started using a habit tracker I have found myself allowing some bad habits to form which are affecting my effectiveness and productivity. One of my ...

Users API for my twitch game

4 minute read

Users API for my twitch game I’ve been working on this game for a few weekends. Here is the flask API I will be using to create users, update their informat...

Risk of Rain 2 Mods

1 minute read

Now on Steam: Risk of Rain 2 is a multiplayer roguelike 3D sequel to Risk of Rain. Prereqs: Do...

The Basics of Cryptocurrency Arbitrage

3 minute read

Motivation for this post This post is purely for fun and for sharing some ideas I have had about this space. Many have given up on cryptocurrency since th...

ASCII Otter

less than 1 minute read

Enjoy this otter ascii art. Simple and elegant yet repeatable. This hand drawn ascii art does not inspire, but still gives you the image of an otter swimmin...

Back to top ↑