Advanced Programming I Code Review for Programming Assignment 3

Advanced Programming I Lecture Notes

14 March 2006 • Assignment 3 Code Review


Outline

The Problem

A Big Idea

A Concordance Matrix

Matrix Slices

Slice Manipulations

The Concordance Matrix ADT

Matrix ADT Implementations

Sparse Matrices

a sparse matrix

Which Is Better?

Which Is Better?

The Other ADTs

Dualities

Type Tagging

Test Cases

Big Test Cases

Test Results

Coding Observations

Comment Your Code

Good Comment Characteristics

Example Comments

No STL Containers

Know Your Tools.

int main(int argc char * argv[]) { ... }

Know Your Tools..


int main (int argc,char *argv[])
  ifstream myfile(argv[1])

int main(int argc, char *argv[])
  string infile(argv[1])
  ifstream fin
  fin.open(infile.c_str())

int main (int argc, char ** argv)
  if (argc == 1) { cerr << emsg; exit(0) }
  string filename = argv[1]

int main(int argc, char** argv)
  if (argc != 2) cout << emsg
  ifstream infile(argv[1])

Check Array Accesses

Pointer Errors Are Nasty

$ ./concord smith.txt
? 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Segmentation fault (core dumped)

$ ./concord smith.txt
? 2 3 4 5 6 7 8 9 10 11 12 13 14
and as be it not of that the
? 2 3 4 5 6 7 8 9 10 11 12 13 14 15
and as be it not of that the
? 

Program Defensively

Obey The Rule of Three

Obeying The Rule of Three


This page last modified on 16 March 2006.

This work is covered by a
Creative Commons License.