Category Archives: Uncategorized

Love Letters to a Machine

Love letters are wonderful and romantic.  The very notion that the written word can help initiate or nurture a lifelong commitment is awe-inspiring.

From a practical standpoint, though, what is a love letter?  There are four important attributes I want to focus on.

  1. Literary: A love letter is a written form of communication.  You can’t have love letters without literacy.  In fact, some forms of love letters (sonnets, for example) put severe syntactic restrictions on the writer.  The writer has to work hard to put thoughts and feelings into the right structure.
  2. Dyadic: A love letter is a message between members of a pair—the writer and the reader.  As such, as much as I care about you, a blog post does not count as a love letter.
  3. Aspirational: A love letter makes the reader aware of the writer’s desires or wishes. It isn’t about facts and figures, but about revealing the writer’s hopes and dreams.
  4. Petitionary: A love letter beseeches the reader to share in the goals of the writer.  Ideally, the two adopt a common purpose and the writer achieves a state of delight as a result.

My thesis is that, in a manner of speaking, a computer program is a love letter to a machine.

Ok, maybe that’s a bit of a stretch.  Let’s compare.  Here’s a snippet of a computer program—a beautiful algorithm known as binary search.  It can be used for finding a target value in a sorted list of values, like looking up a name in a phonebook or a word in the dictionary (back when we had to do that sort of thing):

int binary_search(int A[], int key, int imin, int imax) {
  if (imax < imin): return KEY_NOT_FOUND;
  else {
      int imid = midpoint(imin, imax);
      if (A[imid] > key) return binary_search(A, key, imin, imid-1);
      else if (A[imid] < key) return binary_search(A, key, imid+1, imax);
      else return imid;
    }
}

Ah, lovely.  Now, here’s a snippet of a recent love song (from Jason Mraz):

Well open up your mind and see like me
Open up your plans and damn you're free
Look into your heart and you'll find love love love love

 

There are some important similarities.  They are both a little cryptic (“imid”?  see what like me?).  They both provide instructions on how to find something (key and love, respectively).  Both may or may not be successful (KEY_NOT_FOUND, love not won).  But, they are definitely not the same.  The song is a bit more—I don’t know—soul stirring.

Nevertheless, programs share the four features of love letters I enumerated earlier.  Programs are literary—they are written down, sometimes under severe syntactic constraints.  They are dyadic—the programmer is the writer and the computer is the reader.  They are aspirational—they express the programmer’s wish for what should happen.  Finally, they are petitionary—the programmer entreats that the computer adopt these goals as its own.

In most modern languages, the wish is expressed in a detailed, imperative style.  Programs read more like recipes (“add a stick of butter”) or scripts (“Luke, saddened by the loss of Obi-Wan Kenobi, stares off blankly as the robots look on”) or driving directions (“Turn left at the second light”) than wish lists.  But, some languages do support a declarative programming style.  Instead of giving step-by-step instructions, the programmer can describe the desired state of affairs and the computer has some latitude in how to bring it about.

Nevertheless, I really like this analogy.  One of the things that I find interesting and significant is that love letters require proficiency with written language.  This skill can take people a decade or more to develop.  Quite honestly, in spite of all that work, most people aren’t all that good at it.  I’ve been writing professionally for 24 years, and I still look with envy at the Pinkers and Gladwells of the world who make me appear to be doodling with a crayon.  Writing well is supremely difficult.  But, you don’t have to be J. K. Rowling to compose shopping lists or post youtube comments.  Or to pen love letters, for that matter.  The effort it takes to learn to write is worth it even if only a handful of people ever read your words.  It’s that valuable.  Your thoughts are your own and writing is the skill that lets you share it with other people you want to connect with.  Just because Shakespeare said it better than you ever could, doesn’t mean you shouldn’t try to say it.

Programming is like that.  There are gifted programmers who change the world and make a good living writing code.  You’ll never be that good at it.  I’ll never be that good at it.  Nevertheless, even if you never sell a line of code, it’s worth being able to program.  How else can you tell machines what you really want?