Marc was recently hired at a small company whose primary source of revenue came from a C++ based web-application. One his first day, his boss gave him a thoughtful heads-up about the code in the system: the guy before Marc was a really bad coder and had unfortunately contributed to a large portion of the application. But it was all good, assured the boss, because the bad coder was gone and they were ready to move on into a new era of quality.

After a few days of learning the system and seeing the bad code in person, Marc's only consolation was the fact that he'd get to rewrite a lot of the bad code. One piece of the system -- how SQL commands were executed by writing to a file name, passing the filename to a function, then reading back a results file -- struck him as so rediculously bad he felt like he had to joke about it with his boss ...

void execSqlCommand(int ActionFlag, char * sqlFileName, char * outputFileName)
{
  int response=0; 
  long x=0, z=0;
  char * systemCall = malloc(sizeof(char) * 1024);

  switch (ActionFlag)
  {
    case 0: //execute sql
      strcpy (systemCall,"isql -U sa -P -S 192.168.3.118 -d ORGDB -n");
      
      strcat (systemCall," -i");
      strcat (systemCall,sqlFileName);
      
      strcat (systemCall," -o");
      strcat (systemCall,outputFileName);
      
      response = system (systemCall);
      break;
    case 1: //delete command file
      strcpy (systemCall,"DEL ");
      strcat (systemCall,sqlFileName);
      response = system (systemCall);
      break;
    case 2: //delete both command and output
      strcpy (systemCall,"DEL ");
      strcat (systemCall,sqlFileName);
      response = system (systemCall);

      strcpy (systemCall,"DEL ");
      strcat (systemCall,outputFileName);
      response += system (systemCall);
      break;
  }
  
  // wait for database to return data.
  z = 0; for (x=0;x< 999999900;x++) {z++;} 
  z = 0; for (x=0;x< 999999900;x++) {z++;}

  return;

}

// C Cheat-Sheet [from Alex]
// strcpy(a,"somestr") --> a = "somestr" // strcat(b,"something") --> b = b + "something"
// (I haven't used C/C++ in nearly a decade, and I almost
// forgot these myself)

His boss sternly replied: "Umm ... I wrote that. What's wrong with it?" His boss seemed like a kidder, so Marc eagerly awaited a smile and a laugh. It never came. It's going to be a loooong road towards that new era of quality ...

(NOTE: DNS Issues -- site may be up and down while they are resolved UPDATE: All Good now, let's hope; the outage did make the news, though)

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!