Debugging

OCW Scholar

« Previous | Next »

Session Overview

Photograph of a moth taped into a lab notebook.

This lecture starts with a brief explanation of why floating point numbers are only an approximation of the real numbers. Most of the lecture is about a systematic approach to debugging.

Image courtesy of the Naval Surface Warfare Center, Dahlgren, VA.

Session Activities

Lecture Videos

About this Video

Topics covered: Binary, float, floating point, approximations, debugging, runtime error.

Resources

Recitation Videos

About this Video

Topics covered: Recursion, divide and conquer, base cases, iterative vs. recursive algorithms, Fibonacci numbers example, recursive bisection search, optional and default parameters, pseudo code, introduction to debugging, test cases and edge cases, and floating points.

Check Yourself

Why do computers use binary representations?

View/hide answer

It's easy to build hardware with two states, on and off.

 

 

Why shouldn't we test for equality with floats?

View/hide answer

Because computers use binary, floats are actually very close approximations of the actual values. Testing for equality can result in an unexpected error, so it's better to determine whether two numbers are close enough for our purposes rather than precisely equal.

 

 

When debugging, how can you ensure that the values in your program are the ones you think they are?

View/hide answer

Use print statements.

 

 

Problem Sets

Problem Set 3: Wordgames (Due)

In this problem set, you'll implement two versions of the 6.00 wordgame! Don't be intimidated by the length of this problem set. It's a lot of reading, but it is very doable.

Let's begin by describing the 6.00 wordgame: This game is a lot like Scrabble or Text Twist, if you've played those. Letters are dealt to players, who then construct one or more words out of their letters. Each valid word receives a score, based on the length of the word and the letters in that word.

Problem Set 4 (Assigned)

Problem set 4 is assigned in this session. The instructions and solutions can be found on the session page where it is due, Lecture 10 Hashing and Classes.

Further Study

These optional resources are provided for students that wish to explore this topic more fully.

Readings

After watching the lecture, you may want to read some of the following resources:

 

« Previous | Next »