AOIT Introduction to Programming Unit 4 Lesson 11

  • Slides: 11
Download presentation
AOIT Introduction to Programming Unit 4, Lesson 11 Advanced Debugging Techniques Copyright © 2009–

AOIT Introduction to Programming Unit 4, Lesson 11 Advanced Debugging Techniques Copyright © 2009– 2015 NAF. All rights reserved.

Debugging is a methodical process • In professional environments, debugging is a methodical process

Debugging is a methodical process • In professional environments, debugging is a methodical process of finding and reducing the number of bugs, or defects, in computer programs. What does methodical mean? • How debugging relates to testing: • Testing finds bugs; debugging gets rid of them. • Testing is an important part of the debugging process. • Sophisticated tools (e. g. , tracing tools, debuggers) help professional programmers.

Part of debugging is prevention • Problems can be avoided by using important programming

Part of debugging is prevention • Problems can be avoided by using important programming “best practices. ” • Emphasize well-thought-out program design: problem statement, requirements, algorithm, pseudocode. • Use “chunking” and strict program organization by section: prolog, environment setup, initialization, processing, cleanup. • Insert meaningful comments in the code. How does strict program organization help to avoid bugs? How do comments in the code help to avoid bugs?

Shorter programs don’t usually require a formal, methodical process • With simpler programs, debugging

Shorter programs don’t usually require a formal, methodical process • With simpler programs, debugging is somewhat more haphazard and heuristic: • Eliminate obvious syntax errors first. • Observe program output. • Use trial and error. What does heuristic mean? What kind of tests in Guess-A-Number were called heuristic, and why?

How did you find the bugs in the Buggy House program? # output from

How did you find the bugs in the Buggy House program? # output from house_buggy. py How many bugs are there? What are they? # output from house. py

An incorrect value is hard-coded into the program Did you find this bug? If

An incorrect value is hard-coded into the program Did you find this bug? If so, how did you do it?

The for-loops three times instead of four Did you find this bug? If so,

The for-loops three times instead of four Did you find this bug? If so, how did you do it? What debugging code has been inserted into the program that would have helped to track down the bug?

There is dead code that should be removed Did you find this bug? If

There is dead code that should be removed Did you find this bug? If so, how did you do it?

Longer, more complex programs require a formal, methodical debugging process • Complex programs always

Longer, more complex programs require a formal, methodical debugging process • Complex programs always have bugs, and the bugs are often more difficult to find. • Because longer, more complex programs have more bugs, you need to use more sophisticated techniques to find them. • You were introduced to this methodology in the Hangman program. What code were you given in Hangman for debugging? What was the code testing?

Debugging code was inserted in the Hangman program What statement is featured in all

Debugging code was inserted in the Hangman program What statement is featured in all this debugging code?

Complex programs require a sophisticated and multifaceted debugging approach • Well-thought-out program design •

Complex programs require a sophisticated and multifaceted debugging approach • Well-thought-out program design • Well-organized program with meaningful comments • Careful coding using the “chunk” approach • Paper-and-pencil code reviews • Testing/debugging code built in to the program (the print statement plays a major role) • Multiple approaches, including heuristics • Experience gained over time