Chapter 6.8 - Debugging Caesar Cipher
Time Estimate: 45 minutes
6.8.1. Introduction and Goals
In this lesson, we will learn more about the types of errors you might get in a program, including tips for identifying, fixing, and preventing them.
Learning Objectives: I will learn to
identify and correct errors in a program
explain the difference between syntax errors and semantic errors
Language Objectives: I will be able to
use target vocabulary, such as syntax error, semantic error, and run-time error while fixing errors in an app, with the support of concept definitions and vocabulary notes from this lesson
6.8.2. Learning Activities
First, watch the video below. After watching the video, try to identify and correct the errors in the Caesar Cipher app and then answer the questions about debugging. When watching the video, look for these important terms and concepts:
Bug - In computer programming, a bug is an error or defect that prevents the app from working the way it is supposed to.
Debugging - The process of removing errors from computer hardware or software.
Logic Error - A mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly. Also referred to as a semantic error.
Syntax Error - A mistake in the program where the rules of the programming language are not followed.
Activity: 6.8.2.1 YouTube (g48gxSkOeik)
Activity
The activity for this lesson is to debug a version of the Caesar cipher app. There are at least five errors in this version of the app. See if you can find and correct them all! To get started, open App Inventor with the Caesar Cipher Buggy template.
Here are some hints and suggestions.
If you see a run-time error message, read it carefully - it's trying to tell you where the bug is. A run-time error is a mistake in the program that occurs during the execution of a program. Programming languages, such as MIT App Inventor, define their own run-time errors. For example, if the run-time error complains about exceeding the length of the text, then the loop going through the text letter by letter did not stop at the end of the text.
The bugs can be in both the encryption and decryption steps. So make sure you test the app thoroughly, with appropriate inputs. When you are testing this app, only type in lowercase letters in the plaintext textbox to encrypt, and only type in uppercase letters in the Ciphertext textbox to decrypt.
You are may see more problems if you encrypt longer rather than shorter messages.
If you are having trouble locating a problem, use a Notifier or use Label1 to display intermediate values of local or global variables.
You may also compare this code to your finished Caesar Cipher app from the previous lesson.
Use App Inventor's Do It tool to evaluate expressions and intermediate values. Here's a short video on how to use Do It.
6.8.3. Summary
In this lesson, you learned how to:
Learning Objective CRD-2.I.a: For errors in an algorithm or program: a. Identify the error.
Learning Objective CRD-2.I.b: For errors in an algorithm or program: b. Correct the error.
A logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly.
A syntax error is a mistake in the program where the rules of the programming language are not followed.
A run-time error is a mistake in the program that occurs during the execution of a program. Programming languages define their own run-time errors.
6.8.4. Self-Check
Here is a table of some of the technical terms discussed in this lesson. Hover over the terms to review the definitions.
debugging
computer bug
syntax error
logic/semantic error
run-time error
Q-2: True or False: In computer programming, a bug is an error or defect that prevents the app from working the way it is supposed to.
A. True
B. False
Q-3: In computer programming, syntax is the __________ that determines whether statements are correctly formulated.
A. set of rules
B. programmer's knowledge
C. programming language
D. compiler
Q-4: A ____________ error occurs when a programming language’s rules are broken. This type of error can be detected by the compiler which will provide an error message.
A. semantic
B. syntax
Q-5: A ____________ error occurs when a programmer inadvertently puts code that is syntactically correct, but does not do what the programmer intended it to do.
A. Semantic
B. Syntax
Q-6: True or False: Semantic errors can be detected by the compiler.
A. False
B. True
Q-7: Which of the following are examples of semantic errors in App Inventor? Check all that apply.
A. Attempting to set PaintPot's Canvas1.PaintColor to red using a text block.
B. The PaintPot ButtonMinus.Click event adding 1 to dotsize.
C. The PaintPot ButtonRed.Click setting the Canvas1.PaintColor to blue.
D. Coding duplicate Canvas1.Touched event handlers in PaintPot.
Q-8: Your classmate discovers that their LightsOff app has a bug in it. What should he/she do to debug their app?
A. Form a hypothesis about what might be wrong, design an experiment to test their hypothesis, perform the experiment, debug, and then retest the app.
B. Rebuild the app and then retest the app
C. Immediately start changing code and retest the app.
D. Form a hypothesis and then retest the app.
6.8.5. Reflection: For Your Portfolio
Answer the following portfolio reflection questions as directed by your instructor. Questions are also available in this Google Doc where you may use File > Make a Copy to make your own editable copy.
Complete the following table describing each of the 5 bugs in the Caesar Cipher app. Explain what the bug is, how to fix it, and the type of error (semantic or syntax). If you wish, you can take a picture of your corrected blocks and then annotate it to identify and describe the bugs you fixed.
Code with error (screenshot or description)
What the bug is
How to fix the bug
Syntax or semantic error?
1
2
3
4
5
Portfolio Reflection Questions
Make a copy of this document in your Portfolio Assignments folder and answer these questions in the spaces below. Once complete, turn in this assignment according to the steps given by your teacher.
6.8 Debugging Caesar Cipher Curriculum Page
Answer the following question:
1. Complete the following table describing each of the 5 bugs in the Caesar Cipher app. Explain what the bug is, how to fix it, and the type of error (semantic or syntax). If you wish, you can take a picture of your corrected blocks and then annotate it to identify and describe the bugs you fixed.
Answer
Code with error (screenshot or description
What the bug is
How to fix the bug
Syntax or semantic error?
1
2
3
4
5
Last updated