Annoucements - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Annoucements

Description:

Annoucements. Copy of textbook (1st edition) is in the library on two hour reserve ... Abstraction -- don't get bogged down in details until you must ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 17
Provided by: timoth90
Category:

less

Transcript and Presenter's Notes

Title: Annoucements


1
Annoucements
  • Copy of textbook (1st edition) is in the library
    on two hour reserve
  • Reminder, homework 0 due Friday
  • You should be starting programming assignment 1
  • Shelby Rollins - tell me your e-mail address

2
CS 162 - Spring 2005
  • Chapter 7, 8 - Problem Solving, Testing and
    Debugging

3
How do you go about solving complex problems?
  • Abstraction -- dont get bogged down in details
    until you must
  • Take small steps (at the right level of
    abstraction!)
  • Sometimes look at the problem top down, sometimes
    bottom up, usually a little bit of both

4
Your Programming Assignment
  • Take, for example, your first programming
    assignment.
  • Write a program that reads lines from the input.
  • Which are then broken into words
  • ... Which are then scrambled and output

5
Top Down Design
  • Top down development -- first address the problem
    of how to read a line of text from the standard
    input. Test by writing to the standard output
  • Note that the test code (often called a stub)
    isnt going to be part of the final application.
    But it helps you get this part right.
  • How do you test? What are some boundary cases?
  • When you have this part working, go on ..

6
Next Step, Break into Words
  • Next step. After reading a line of text, break
    into words.
  • Questions -- how to find start? How to find end?
    How to display the result so you know it is
    correct?
  • Testing? What are some exceptional conditions?
    Boundary conditions?

7
Next Step, Scramble Words
  • Next Step. Having found a word, how to scramble?
  • Loop over all but first and last character,
    select another character, and swap.
  • Again, test to make sure you are doing right
    thing. What are good test cases?

8
Bottom Up Development
  • We described an approach that was top down.
    Sometimes it is useful to address a problem
    bottom up. (Maybe you have only a part of a
    larger task, maybe a particular problem seems
    difficult and/or interesting)
  • Example, suppose you want to address the scramble
    aspect by itself.

9
Word Scramble as separate problem
  • So now we are thinking of word scramble as a
    problem that is independent of the larger task.
    First, describe the problem in terms of input/out
  • String wordScramble(string word)
  • Result has same size as argument, same letters
    but in different positions, first and last letter
    unchanged.

10
Write and Test Independently
  • Develop your version of wordScramble.
  • Create a main program that finds or creates input
    to wordScramble, calls the function, and prints
    or tests the result.
  • Called a test harness, sits around the code under
    test. Can be in the same class, or another class.
  • Process of testing individual methods is called
    unit testing

11
Testing, Deja Vu
  • Testing with test harness has same issues as
    testing with stubs.
  • What are exceptional (or boundary) cases? What
    are normal cases? How do you tell if you have
    the right answer?

12
Integration Testing/ Regression Testing
  • You test various pieces by themselves. Put them
    together into larger pieces. Test the pieces, put
    them into larger pieces, test again. This is
    termed integration testing
  • You will likely still have bugs. After you fix
    each bug, you must run all the tests that you
    have tried previously to make sure they still
    work. This is termed regression testing.

13
Debugging
  • Despite the best efforts at design, development,
    and testing, your code will still likely contain
    errors. Programming is one of the most difficult
    things people do!
  • When you have errors, how do you find them?

14
Steps in Debugging
  • Reproduce the error. Make sure you can show it
    repeatedly.
  • Simplify the error. Find the simplest test case
    or set of values that show the error.
  • Divide and conquer. Use breakpoints, print
    statements, to locate where the error occurs
  • Know what your program should do.

15
Steps in Debugging, cont
  • Keep an open mind. "When you have eliminated the
    impossible, whatever remains, however improbable,
    must be true"
  • Look around. If you don't see anything at the
    point the error is manifest, the mistake is
    probably earlier.
  • Look at the details. The simple errors are the
    hard ones to see.

16
For Next Time
  • Read Chapter 9 (Chap 11 in 2nd edition)
  • Start Programming Assignment 1
  • Do homework 0 (due on Friday in class)
Write a Comment
User Comments (0)
About PowerShow.com