PAT - Testing and Debugging (Lesson)

Testing and Debugging

What happens when a program is compiled? And what, you ask, is compile?

What happens when a program is compiled?  And what you ask is compile?

To compile is to use a compiler for your program code, source code, and translate that code into machine language. Your program code is the source code. Machine language code is also called object code or bytecode. An interpreter may further interpret the bytecode a line at a time for execution.

The Alice coding language is a high level language source code, a language that uses words of your language and math concepts. Machine code, or object code, is a low level language which is often in binary form. Creating the machine code is another abstraction from the programmer at our level. We do not need to know how it works, but it does.  

To test a program is to compile the code, and with a successful compile run the code to make sure that the code works as designed. This brings up two types of errors or bugs: compile time and runtime. Compile time errors are found by the compiler or the IDE, integrated development environment. An example of an IDE is the Alice front that assists us in creating the program. The IDE is a user-friendly programming environment called an application program (ours is Alice). The following items are included with most IDE's

  1. an editor for the creation of source code
  2. a graphical user interface (GUI)
  3. a compiler
  4. a method to test and debug your program

Compile time errors prevent the program from running. These bugs require the programmer to understand the hints of the programming environment as you write the code or read the error message that the compiler provides and then take action. This action is to correct the problem because the program will not be able to execute with any of the upfront errors found. Thus the name compile time errors.

Watch the video below and see how the Alice programming environment, the IDE, will help you code correctly.

Runtime Errors

Runtime errors happen during program execution. The program may or may not run the way we wish. The program may go off track from what we thought and totally "get lost". This error is not the computer's but again the programmer's. We find this out in Alice by telling Alice to "run" our program.  

Watch the next video to learn some steps of debugging a program of runtime errors. You must not be satisfied that the program runs. A programmer is satisfied when the program operates in the best way possible for the situation. Sometimes that means adding items that you did not think of originally.  

Control User Input

In this next video, we fix and control userInput (camelCase variable) to create a controlled runtime for the program. Would we want the hare to jump 1,000 times?

Bugs

PAT_DebuggingCatWolfing.pngNow we understand better what testing and debugging is all about. The worst thing to have in a program is a "bug". At some time, someone using the program will come across the error, usually an odd item being entered into the program that is not checked for. The odd item then gets into code that does not know what to do with it and the program fails. Alternatively, the program could get stuck in an infinite loop, no way out, creating eventual computer memory failure or requiring the user to terminate the program by turning off the computer. The worst thing is for the program to "crash", fail when someone was using it. 

Remember that a "bug" may not make the program fail or not run, but it could provide wrong answers or do something that does not seem to be in character of what the program should do, i.e. a cat barks instead of meows. The program doesn't stop working, it's just wrong.

IMAGES AND VIDEOS CREATED BY GAVS.