Jokes in Code
© 26 Oct 2013 Luther Tychonievich
Licensed under Creative Commons: CC BY-NC-ND 3.0
other posts

Reflections on humor.


This week while teaching my Introduction to Programming class I wrote the following code as part of a demonstration and discussion:

public class Dinosaur { public void eat(MarbleInABirdCage m) { this.setColor("Blue"); } }

The students looked at it in silence for a moment and then I said “‍because, you know, they choke.‍” Many of the students burst into laughter.

I don’t think there is any way to translate that into English and have it come out funny. Admittedly, much of the humor then was in the delivery and context; but there is also something fundamentally more humorous about some things in one language as compared to another. That a dinosaur will choke and turn blue if it eats a marble in a bird cage is strange, but not much more than strange. That you can say it in a language designed entirely to be a practical tool for getting tasks done adds that extra unexpected twist that allows it to be turned into a joke.

Humor fascinates me, particularly the humor of witticism and joke. The basic mechanism seems to be bump the mind out of its groove, but do so gently enough that it goes a new direction without much effort, obviously enough that confusion does not result, quickly enough that the destination cannot be anticipated, and into a new groove that seems, in its way, just as natural as the old one. Humor shares something with a Eureka! moment in that there is a single moment when it all clicks into place, but there is no substance behind it, no revelation or new understanding. Indeed, I’ve seen a few jokes spoiled because their punch line turned out to be instructive and looks of enlightenment replaced the hoped-for looks of amusement.

The language you use to deliver a joke helps to define what the grooves are, both the ones you can bump people out of and the new ones into which they can fall. Part of the humor in the example above derives from the fact that code often expresses what but rarely suggests why; the silly explanation I gave mirrors the all-too-common “‍Oh, so that’s why it’s doing that‍” moment that happens when reading code. Those grooves aren’t there in most human languages. In English to leave out the why is an act of omission; in Java, even after the why is known the code doesn’t change because whys aren’t part of the language.

All of this begs the question: how do routinely witty people think up all of these parallel grooves to bump peoples’ minds into? In the joke above it came because I was trying to adapt on the fly to a strange set of classes, fields, and methods that students had provided. I needed some method that used both Dinosaur and MarbleInABirdCage so my brain, frantically scrambling over hundreds of options, arrived at “‍eat‍” and then, once it had that, tried to find some kind of change of state that would work with the available fields and methods. But I tell many jokes and rarely am I aware of that kind of urgent scrambling of neurons looking for something that will fit the situation.

Where do witticisms come from? And even knowing what some of them are, why are the pleasurable to hear?

Looking for comments…

Loading user comment form…