Assignment 1 Code Review

Advanced Programming II - 6 February 2001


Code Size

newlinessemicolons
16120742
541361644
551551657
671751760
761792064
781872367
871883177
882693289
932723394
9929434132
10532137134
11041


The Basics - Magic Numbers


The Basics - Use Meaningful Names

static int flag = 1;
static int flag2 = 0;
if (*text == '<' || flag2 == 1)
flag2 = 1;
flag2 = 0;
flag = 0;
if (*text == ' ' || flag == 0)
flag = 0;
flag2 = 0;
if (flag == 0)
flag = 1;


The Algorithm


Storage Management


Dynamic Storage Management


A Storage Tragedy

static char tag[10];
static int tagindex=0;

// and so on

if (check_tag == 0 && tag_found == 0) {
  tagindex=0;
  tag[tagindex]=toupper(*text);
  tagindex++;
  }
else if (check_tag == 1 && tag_found == 0) {
  if (!isspace(*text) && *text != '>') {
    tag[tagindex]=toupper(*text);
    tagindex++;
    }
  else {
    tag_found=1;
    tag[tagindex]='\0';
    if (!strcmp(tag, "FONT"))
      font_flag=1;
    else
      font_flag=0;
    }


A Storage Disaster

void disable_font(char *text, unsigned char_cnt) {

  char tmp_char, * tmp;
  static int flag = 0;

  *(text + char_cnt) = NULL;
  while (*text != NULL) {
    // and so on


A Storage Problem


Avoid Complexity


Duplication Complexity


Almost Duplication Complexity


Nesting Complexity


2 Complexity


How to Cope


This page last modified on 27 February 2001.