Lecture Notes for CS 509, Advanced Programming II

10 February 2004, Assignment 1 Code Review


Outline


Design


Top-Down Design and Stepwise Refinement


Top-Down Design Problems


Design by Wishful Thinking


What's the Problem?


At the Wishing Well


Now what?


Balancing Tags


Implementing Tag Balancing


Tags

class tag

  bool is_open_tag() { ... }

  bool matches(const tag & t) { ... }

  tag(bool open, string name) { ... }


Test cases

  1. empty test

  2. garbage test

  3. < hello > < /hello > test

  4. </hello> <hello> test

  5. </hello> test

  6. <hello> test

  7. <hello test

  8. <hel lo> </hello> test

  9. <> </> test

  10. <a> <b> </b> </a> test

  11. <a> <b> </b> </a> <a> <b> <c> </c> </b> </a> test


What Happened

c n - + y
1 0 0 0 0 7
2 0 1 0 3 3
3 0 2 0 0 5
4 1 1 1 1 3
5 1 1 1 1 3
6 0 1 1 1 4
7 0 2 0 1 4
8 0 2 0 2 3
9 1 3 0 1 2
10 0 2 0 0 5
11 0 2 0 0 5


Follow Directions


Be Wary of Duplicate Code


Factor Duplicate Code


Follow Directions, Part 2


Don't be Sloppy


Favor Local Variables


Understand Array Accesses

***
*** <> </> test
***

!!! Error message expected; actual output:

---
Accessing index 0 in a string of size 0.
../../test-code: line 10: Abort ./$ex <$ifile
---


Test Your Assumptions


Points to Remember


This page last modified on 25 March 2004.