Skip to main content

CSC 151.03, Class 23: Debugging

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Approaches to debugging
  • Lab
  • Debrief

News / Etc.

  • I hope you had a wonderful fall break.
  • I was less efficient in grading than I had hoped. You get snacks instead of exams. Sorry.
  • Today’s lab is all new for this semester. Let’s hope that our lab on debugging doesn’t have too many bugs.
  • DrRacket’s debugger crashes in some situations. Make sure to save before debugging.

Upcoming Work

Extra credit (Academic/Artistic)

  • They Call Me Q, Tonight at 7:00 p.m. in Harris Concert Hall.
  • MASSS talk on text analysis with R Tuesday at 11 a.m. somewhere in Math.
  • Learn about the CS major, Tuesday at 11 a.m. in Science 3821.
  • Saving Brinton, Wednesday at 7pm in the Strand.
  • Gates Lecture, Wednesday at 7:00 p.m. in JRC 101. Professor Sylvester Johnson, Director of the Humanities, Virginia Tech, talk will examine the twentieth-century roots of contemporary national security responses targeting American Muslims as state enemies.
  • Convocation Thursday (11 am in JRC 101).
  • Protest Bot workshop, Friday 4pm in Burling 1st.

    Bots are small automated programs that index websites, edit Wikipedia entries, spam users, scrape data from pages, launch denial of service attacks, and other assorted activities, both mundane and nefarious. On Twitter bots are mostly spam, but occasionally, they’re creative endeavors. Mark Sample will lead participants in the creation of bots that can “reveal the injustice and inequality of the world and imagine alternatives. … that question how, when, who and why.”

Extra credit (Peer)

  • Soccer Wednesday, we think.
  • Advocates Meet and Greet (with ice cream) Thursday 7pm-9pm in JRC 209.
  • Submit to the Grinnell Review (grinnellreview.com)
  • Pioneer Weekend in about two weeks: A one weekend innovation challenge

Extra credit (Misc)

  • Academic Success Workshop, 11am, JRC 226. “Finding your focus”

Other good things

Questions

Approaches to debugging

What do you do when your procedure doesn’t work?

  • Read the error message
    • Good idea!
    • Assumes there is an error message.
    • Unfortunately, not all error messages are helpful.
  • Use display statements.
    • You should predict what will be displayed before running the program.
    • In other CS courses, we tend to discourage these, but there is certanly a place for them in some situations.
  • Throw it away and start again.
    • Necessary in some situations. Rethinking the problem is helpful.
  • Apologize to the computer.
    • Not necessary.
  • Curse your professor.
    • That explains so much of my life.
  • Check parantheses.
    • Way too often, we have the logic correct but the parentheses wrong. Checking parentheses (often by re-indenting) is a great strategy to handle those kinds of errors.
    • Formatting helps with this.
  • Think about the code from the inside out.
    • Good strategy
    • More generally, walking through an example by hand to make sure it seems to do what you think it will is helpful.
  • Today’s lesson: Use a debugger
  • Explain the steps to someone else, preferably a human, but optionally a stuffed animal, a marker, your stress ball

Lab

Writeup: 4d & 5d.

For 4d: Suppose we have the list '("alpha" "beta" "a" ...). The length of the car is larger than the length of the cadr, so we want to “throw away” the cadr. That means that we should recurse on '("alpha" "a" ...).

Debrief

Important issue not mentioned in the lab: You can check return values when the arrow is on the right parenthesis.

Writing the test suite: If I were called upon to test longest-string, I would probably choose four strings of different lengths and write a test for each permutation of those four strings. While 24 tests is a lot, I expect that there are procedures that will fail for only one of them.