Debugging

September 9, 1947

First bug

“The team at Harvard University in Cambridge, Massachusetts, found that their computer, the Mark II, was delivering consistent errors. When they opened the computer’s hardware, they found … a moth. The trapped insect had disrupted the electronics of the computer.”

Sep 9, 1947 CE: World’s First Computer Bug

How to catch bugs

  • Error message (easiest type to solve, the message tells you what to fix)

For all other bugs, we need to know what the correct/expected behavior is in order to be able to identify when the application is not behaving in the way we expect/want it to behave.

  • Unit testing
  • Bug reports from users

Once we have a way to check that our code is not doing what it should be doing, we need to isolate (or find) where the bug is.

How to catch bugs

  1. Write a test that is minimal (small, repeatable) that trigers the bug
  2. Find where the bug is being generated
  3. Change the code to test your hypothesis of where the bug is being generated (change one thing, test it, repeat)
  4. Fix the bug
  5. Can this bug happen somewhere else in the code?
  6. Add test cases to catch the general bug type (Regression Test)

Practice

Download the provided buggy code and with your table mates, fix all bugs

Practice

The first team to show me all tests passing, and showing me where the bugs were (make sure you write down changes to the code) will win 1 extra credit point.

User bug report:

I get an error when I try to create a game with 6 players, 10 cards per hand