Never, ever hire a programmer without reading their code

Suppose you wanted to hire a singer. You interview a bunch of people. One of them comes with all kinds of good recommendations from their music teachers. They have lots of A's in their music classes, they have a diploma from a well-known music school, all kinds of credentials.

Wouldn't you still want to hear them sing?

This summer I got a job at a company finishing up a program that had been written by an undergraduate who graduated from UB. After he'd graduated, he'd left for the fields of Virginia and left behind a program which my boss tells me is 80% finished. Recently I came upon the following datafile.

c1 = 10
c2 = 14
c3 = 31
c5 = 81
(The actual file had about twenty lines). The program itself had a bunch of variables of the form c[0-9]+ of course. They were constants in a bunch of equations that the program evaluates.

So suppose we wanted to add a new variable to the datafile because we've added a new equation to the program. Wouldn't it seem reasonable to add a line on the end like c6 = 24? It looks like the program reads the variable name and then stores the value after the = into that variable, right? Don't answer so fast.

Leaving aside the question of whether these are good variable names (they're not) and leaving aside the question of whether there were comments in the code or in the datafile explaining what each variable was (there were none), let's examine the code that my predecessor wrote to read this datafile.

open INPUT as "datafile.dat"
Read one line from INPUT into Buffer
c1 = word 3 of Buffer
Read one line from INPUT into Buffer
c2 = word 3 of Buffer
Read one line from INPUT into Buffer
c3 = word 3 of Buffer
Read one line from INPUT into Buffer
c5 = word 3 of Buffer
So what we really have here is a program that reads a line from the datafile and puts the third word of it into c1, and then takes the third word from the next line and puts it into c2, and so on for c3, and c5. Always the third word of the line, always those variables and in that order.

So if I go and add c10 = 24 to the end of the file, guess what happens? Nothing at all. Or suppose I provide the following datafile (note the blank line):

c1 = 10
c2 = 81

c11 = 14
c12 = 28
The program puts 10 into c1, 81 into c2, and nothing into c3. c5 is empty as well, and c11 and c2 are likewise untouched. Not what you wanted, is it?

Another example

I later found the following code, which stands without explanantion.
to handle buttonUp
  if text of field PipeDiameter of this page is 4
    set text of field PipeDiameter of this page to 6
  else if text of field PipeDiameter of this page is 6
      set text of field PipeDiameter of this page to 8
    else if text of field PipeDiameter of this page is 8
	set text of field PipeDiameter of this page to 10
      else if text of field PipeDiameter of this page is 10
	  set text of field PipeDiameter of this page to 12
	else if text of field PipeDiameter of this page is 12
	    set text of field PipeDiameter of this page to 12
	end
      end
    end
  end
end buttonUp
Of course I can optimize this one a bit. I can get rid of that innermost if statement!

Daniel F. Boyd / boyd@csgeeks.org


(Yes, the language would have allowed the guy to write set the text of field PipeDiameter to min(the text of field PipeDiameter + 2, 12).)