Assignment 1 Code Review

11 February 2003 - CS 509


Assignment 1 Code Review


You Must Program Well


Understand The End-of-Stream Condition


Correct End-of-Stream Testing


Make Valid Vector Accesses


Don't Kill Yourself


The Test Cases


The Test Results


Test Your Code


Design


The Problem


Classify The Strokes


Organize The Strokes


Tidying the Tree


Line Statistics - Newlines

1002003004005006007001500
0 1
10
20 11 1
30 2
40 1
50 1
60 1
70 1
80 1 1
901
Totals12430111


Line Statistics - Semicolons

100200300
0
101
20
30 11
4011
502
602
7012
80 1
90
Totals742


Procedure Statistics

totalpages per procedure
procs1234
22
752
981
112531
1174
22166


Follow Directions


What's Wrong With This Code?

void calcAngleDiff()

  bool found = false
  int i=0, psize = pv.size()
  int idx1 = 0

  for (i = 1;  i < psize; i++)
    if (pv[0].x !=  pv[1].x)
      idx1 = i;
      break;

  adjdiff = 0.0;

  for (i = idx1 + 1;  i < psize; i++)
    if ((pv[0].x > pv[idx1].x  && pv[i].x >  pv[0].x ) ||
        (pv[0].x < pv[idx1].x  && pv[i].x <   pv[0].x ))
      found = true;
      adjdiff =  dv[idx1] - dv[i];
      break;

  for (i = 1; i < psize; i++)
    if (pv[0].y !=  pv[1].y) 
      idx1 = i;
      break;

  enddiff = dv[psize] - dv[idx1];


Procedure Size Matters


Use Named Constants


Points to Remember


This page last modified on 11 February 2003.