## 8. Darn bugs!

Nobody likes to talk about computer bugs. So, I will try to keep this lesson short. All I ask you to do is to read it I won't ask you to write programs with bugs!

### What is a bug?

The origin of the word bug in computer jargon is often attributed to an actual incident where a moth was found inside Harvard University's Mark II computer; apparently this moth had caused the computer to stop working. It was found by the team headed by renowned computer scientist, mathematician, and young naval officer Grace Murray Hopper, who went on to invent the concept of compiler languages in computer programming. Dr. Grace Hopper eventually rose in the U.S. naval hierarchy to the rank of Rear Admiral.

The moth was preserved, taped into Hopper's log book, as shown below. Interestingly, the log book included a note saying, "First actual case of bug being found." as you can see.

###### Picture adapted from the public archive of the U.S. Naval Historical Center

Actually, the word bug in a technological context is attributed by the Oxford English Dictionary to Thomas Edison. According to the Oxford Dictionary, the following text can apparently be found in the March 11, 1889 edition of the Pall Mall Gazette:

> Mr. Edison, I was informed, had been up the two previous nights discovering 'a bug' in his phonograph - an expression for solving a difficulty, and implying that some imaginary insect has secreted itself inside and is causing all the trouble.

It thus appears that the original 'bug', though it was indeed an insect, was in fact imaginary.

Unfortunately, computer bugs, while they are not insects, are also not imaginary.

### Dealing with bugs

In computer jargon, a bug is an error that causes a program to behave in an unexpected way. If you are writing computer programs, you are going to have bugs in them sooner or later - everybody does. Good programmers seek to "remove" bugs or "fix" them as soon as they find that their program behaves unexpectedly.

RUR-PLE has been designed to help you find bugs.

1. The "oil leak" of the robot, leaves a trace behind that allows you to see (trace) the instructions followed by the robot.

2. Each instruction [like `pick_beeper()` below], which is highlighted in the program window as it is about to be executed by the robot.

   Highlighting of instructions can sometimes cause problems; you can turn it on and off by pressing the highlight button.

3. You can "pause" a program as it is running by pressing the pause button . This is similar to what people refer to as setting a breakpoint in a computer program.

4. You can "step through" a program, one instruction at a time, by pressing the (execute one instruction and pause, or step) button .

5. You can change the speed at which the instructions are executed by using the speed controller . The more you move the slider to the right, the faster the program will execute. You can only adjust the speed at the beginning of the program, at which point it will be set for the entire program. For long running program, you can first start running the program quickly, pause it when you reach the point near the unexpected behaviour (the "bug"), and then carefully step through each instruction one at a time.

6. If you find that you started a program and you want to stop it before it reaches the end, you can always press the stop button .

7. At the bottom of the screen is a status bar which displays: 1) which program is loaded; 2) the status of that program; 3) the number of beepers carried by the robot; 4) which world file has been loaded.

8. If you want to restart your program with the robot back at its original starting point when you first loaded a world file, you will need to press the reset world button .

This should be more than enough for now. As you learn more about programming, you will learn other tricks that will help you find bugs and get rid of them!

Beepers - - Building walls