---
title: Eboard 23  Debugging
number: 23
section: eboards
held: 2017-10-23
---
CSC 151.01, 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.
* Congrats to ....

### Upcoming Work

* [Writeup for class 23](../writeups/writeup23) due Wednesday at 10:30 p.m.
    * Exercises 5d and 6d.
    * To: <csc151-01-grader@grinnell.edu>
    * Subject: CSC 151.01 Writeup 23 (YOUR NAMES)
* Read [Randominess and simulation](../readings/randomness) for Wednesday's class.

### 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.
* CS department discussion of major Tuesday at 11 a.m. in 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)

* Heckling Debate, Thursday, Noyce 2021 at 8pm.

### Extra credit (Misc)

### Other good things

### Questions

Approaches to debugging
-----------------------

What do you do when your procedure does not work correctly?

* Throw it away and start again.
    * Sam says: Sometimes that's necessary; there's not always a path
      from incorrect to correct other than "back to the start".  But
      you should usually think a bit more about the existing attempt
      before you throw it away.
* Put in calls to `display`. 
    * Sam says: This approach is primarily useful if you predict what
      the output should be and then compare predictions to actual
      output.
* Check parenthesization
    * Sam says: Incorrect parenthesization is a common error for otherwise
      logically correct programs.  Reindenting helps.
* Read the error message (if you get one) and think about it.
    * Sam says: Some help, some do not.
* Think about the program logic
    * Sam says: Stepping through that ologic by hand helps.
* Sacrifice a class mentor
    * Sam says: I love our class mentors.  Please don't.
* Talk to your stress ball.
    * Sam says: A good variant of the logic.  You can talk to the rubber
      duck, the android figurine, the sleeping person who is your partner,
      your chair, ...
* Walk through the program step by step.
* Ask yourself "What types of inputs do you want?  What types of outputs 
  should you have?"

Lab
---

```
(define longest-string-tests
  (test-suite
   "tests of longest-string"
   (test-case "singleton lists"
              (check-equal? (longest-string (list "")) "")
              (check-equal? (longest-string (list "a")) "a"))
   ...))
```

```
> (run-tests longest-string tests)
```

Debrief
-------

Where did you come up with the incorrect implementations of `longest-string`?
  : All three are variants of things I've helped student debug.
  : I often make the error that appears in the third version.

Sam, what would you do if you had to write a test suite for `longest-string`?
  : I'd start with some simple lists.
  : I'd make a four-element list of different length strings.
    and I'd try every permutation of that list.  (Yes, I realize that's 24
    different lists.  At some point, I'd write a program to generate
    permutations.) (Ooh!  That's a good homework problem, as long as you
    don't just Google the answer.)

What should we do with the first incorrect one?
  : One option: Deem it badly enough designed that it's not worth attempting.
  : Another option: "Throw away the cadr".

