Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Form 4 Module Problem Solving Lesson 2 Debugging

Uploaded by

Djamen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Form 4 Module Problem Solving Lesson 2 Debugging

Uploaded by

Djamen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Module: problem solving and coding

Lesson: Debugging

1. What is debugging?
Errors in algorithms and code are called ‘bugs’, and the process of finding and fixing
these is called ‘debugging’.
2. Testing vs Debugging
• Testing: to identify any problems before software is put to use
“Testing can show the presence of bugs but can never show their absence”.
• Debugging: locating bugs and fixing them
3. Types of bugs
Types of bugs
• Compile time: syntax, spelling, static type mismatch.
Usually caught with compiler
• Design: flawed algorithm.
• Incorrect outputs
• Program logic (if/else, loop termination, select case, etc).
• Incorrect outputs
• Memory nonsense: null pointers, array bounds, bad types, leaks.
• Runtime exceptions
• Interface errors between modules, threads, programs (in particular, with shared
resources:
sockets, files, memory, etc).
• Runtime Exceptions
• Off-nominal conditions: failure of some part of software of underlying machinery
(network, etc).
• Incomplete functionality
• Deadlocks: multiple processes fighting for a resource.
• Freeze ups, never ending processes
4. Trace tables and algorithm dry run
After code has been written, it is vital it undergoes testing. Without testing, there is a
chance the code will not work.
Trace tables
When designing algorithms, it is common to use a technique known as trace tables.
To create a trace table, map out all of the variables which change (not constants) and write
them down in a column in a table. Each row will then store what assignments happen as
the code is run. Reading through code and noting down values in a trace table is known as
a dry run.
Consider the following code to find even numbers between 0 and 3:
1 for i in range (0, 3):
2 if i % 2 == 0:
3 print(i)
4 i += 1
The following Trace Table could be used to dry run the code:
Program Line Number Value of variable i Output
1 0 -
Program Line Number Value of variable i Output
2 0 -
3 0 0
4 1 -
1 1 -
2 1 -
3 1 -
4 2 -
1 2 -
2 2 -
3 2 2
4 3 -
1 3 -
2 3 -
3 3 -
3 4 -

You might also like