When I was grading for the Software Engineering course, I saw some pretty awful things. Most of the students were actually alright programmers; in fact some were pretty good. The trouble was that neither the really good ones nor the really bad ones came to lecture, so it was impossible to tell who the bad ones were until after it was too late to help them. Mostly, this was because we only began grading the term project --- interactively, as milestones --- late in the term.


Most groups still ended up getting the application to run but there were always one or two students that couldn't explain the system they were supposed to have helped design. During these evaluations, there were three types of teammates. The first was the person that couldn't sit still, wanting to pick up the slack. The second was the person that could only sit still because they, though fairly competent, knew that the application didn't really do what it was supposed to. And then there were the teammates that took sadistic pleasure in watching their randomly assigned partner suffer.


I can only imagine that Ken would have been in this latter group. His odd man out was assigned to pull RRGGBBAA hex values out of XML, adding a new feature to an existing server.


int XMLFeed::Reader::HexToDec(std::string* hex) {
int value = 0; // the value of the current hex char pointed to
   int sum = 0;// the running sum
int intHexLength = hex->length();
   int power = intHexLength - 1; // power is what base 16 is raised to starts at (-1 to account for 0, since zero based)
   char strDigit[1]; //store 1 digit

   //loop through each digit
   for (int i = 0; i < intHexLength; i++)
   {
       strcpy (strDigit, (hex->substr(i,1)).c_str());    //1 = we are examining one digit at a time
       if (strcmp(strDigit, "0") == 0)
           value = 0;
      else if (strcmp(strDigit, "1") == 0)
           value = 1;
       else if (strcmp(strDigit, "2") == 0)
value = 2;
       else if (strcmp(strDigit, "3") == 0)
        value = 3;
       else if (strcmp(strDigit, "4") == 0)
           value = 4;
       else if (strcmp(strDigit, "5") == 0)
           value = 5;
       else if (strcmp(strDigit, "6") == 0)
           value = 6;
      else if (strcmp(strDigit, "7") == 0)
           value = 7;
else if (strcmp(strDigit, "8") == 0)
           value = 8;
       else if (strcmp(strDigit, "9") == 0)
           value = 9;
       else if (strcmp(strDigit, "A") == 0)
           value = 10;
       else if (strcmp(strDigit, "B") == 0)
           value = 11;
       else if (strcmp(strDigit, "C") == 0)
           value = 12;
       else if (strcmp(strDigit, "D") == 0)
           value = 13;
       else if (strcmp(strDigit, "E") == 0)
           value = 14;
       else if (strcmp(strDigit, "F") == 0)
           value = 15;
       else
      {
        mOwner.mLogger.Warn("Input Error: %s is not 0-9 or A-F", strDigit);
         //Should I crash or not?????
         value = 0;
          //exit(1);
       }

       sum += (int) pow(16,power)*value;//this calculates the total, with base=16
       power--;//decrements the power
   }

From the submission: "I particularly like his comment in the final else clause, not to mention the use of the power() function. I shall not try to explain what might have been in his mind when writing the above code, my words are a poor substitute for your own imagination."


There is also one potentially serious portability bug, but that's for you to find. And that's not the end of it. Here's how it was called.


//------- Parse Color String ----------------

//RRGGBBAA <- colour string is in this format
//0 2 4 6  <- indices of color code
strTemp = strBuffer.substr(0,2);
mRed = (unsigned char)HexToDec(&strTemp);
strTemp = strBuffer.substr(2,2);
mGreen = (unsigned char)HexToDec(&strTemp);
strTemp = strBuffer.substr(4,2);
mBlue = (unsigned char)HexToDec(&strTemp);

//at length 8 the color passed includes alpha,
//else it would be six
if (intBufLength == 8)
{      strTemp = strBuffer.substr(6,2);
  mAlpha = (unsigned char)HexToDec(&strTemp);
}

The great thing is that, in the end, everything worked as per the specification. It wasn't pretty and it certainly wasn't efficient, but it worked. And that, folks, is worse that failure.