Assignment 2 Code Review

26 February 2002 - CS 509


Design


Top-Down Design and Stepwise Refinement


What's the Problem?


What's the Solution?


What's a Statement Block?


The First Solution


What's the Next Step?


Finishing Statement Blocks.


Statements


Representing Statements


Line Statistics - Newlines

00020030040050060070080013001500
011
1022
201
301
4011111
501
601111
701
8011
9011
Totals1311264311


Line Statistics - Semicolons

000100200300400500
02
10
2011
301121
403
50
6021
7021
8011
90111
Totals3310511


File Statistics

File
Counts
CountAverage
Lines/File
Avg Semicolons
per File
111476188
21224115
31287128
4216980
5516965
6212545
70
80
90
100
11112438


Procedure Statistics

totalpages per procedure
procs12345678910
33
431
431
6411
71132
7421
1052111
115411
131111
1474111
1495
201523
20173
221363
221831
2219111
22202
242031
28253
312443
33312
5950711
706631


Know Your Tools


Use Named Constants


Factor Common Code


Example Factoring


int ans = check(s.substr(i,j-i));
if (ans ==1) {
  string str = s.substr(i,j-i);
  dq.push_back("n");
  smallv.push_back(str);
  i = j;
  }
else if (ans == 2) {
  string str = s.substr(i,j-i);
  dq.push_back("s");
   smallv.push_back(str);
  i = j;
  }
else if (ans == 3) {
  string str = s.substr(i,j-i);
  dq.push_back("o");
   smallv.push_back(str);
  i = j;
  }
else if (ans == 4) {
  string str = s.substr(i,j-i);
  dq.push_back("e");
   smallv.push_back(str);
  i = j;
  }
else if (ans == 5) {
  string str = s.substr(i,j-i);
  dq.push_back("pl");
   smallv.push_back(str);
  i = j;
  }
else if (ans == 6) {
  string str = s.substr(i,j-i);
  dq.push_back("pr");
   smallv.push_back(str);
  i = j;
  }
else if (ans == 0)
  return false;
int ans = check(s.substr(i,j-i));

if (ans == 0)
  return false;

string str = s.substr(i,j-i);
if (ans == 1)
  dq.push_back("n");
else if (ans == 2)
  dq.push_back("s");
else if (ans == 3)
  dq.push_back("o");
else if (ans == 4)
  dq.push_back("e");
else if (ans == 5)
  dq.push_back("pl");
else if (ans == 6)
  dq.push_back("pr");

smallv.push_back(str);
i = j;

  
int ans = check(s.substr(i,j-i)); if (ans == 0) return false; char * what[] = { "", "n", "s", "o", "e", "pl", "pr" }; assert((ans > 0) && (ans < 7); dq.push_back(what[6]); smallv.push_back(s.substr(i,j-i)); i = j;


Test Cases


This page last modified on 26 February 2002.