Programming Problems

The programmer’s wife says: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”

The programmer comes home with 12 loaves of bread.

I’ve got to be honest here: I have very limited programming experience and probably cannot dissect this joke as thoroughly as a more seasoned programmer would. Nevertheless, I think it’s a cute joke. It’s definitely worth a mention and a cursory explanation.

I do know enough about programming to know that the order and phrasing of instructions is of utmost importance. The programmer’s wife opened with an instruction to get a loaf of bread, then followed with a conditional test: if they have eggs. A conditional test can be either true or false. If the test evaluates true, then the set of instructions immediately following the test is to be carried out.

Unfortunately, the wife left her instructions ambiguous; she told her husband to get a dozen, but didn’t specify what he was to get a dozen of. A normal human would have inferred that he should get a dozen eggs, not a dozen loaves of bread, but a computer is incapable of inferring meaning from ambiguous instructions. Interpreting the instructions in the same way a computer might, the husband assumed that the term dozen referred back to the loaf of bread. Now they can have sandwiches for months, but no omelets.


2 responses to “Programming Problems

  • veqtrus

    As a programmer, I can tell you that this joke, like most programming jokes on the internet, is wrong.

    Converting the joke to code you would get:

    getItem(1, “loaf of bread”);
    if (itemAvailable(“egg”)) {

    If we assume that getItem() with one parameter gets an item previously mentioned, the programmer would get either 1 + 12 = 13 loaves of bread or 1 loaf of bread and 12 eggs, since he would get the first loaf of bread no matter what.

    It is more likely that he would correctly buy 1 loaf of bread and 12 eggs as egg is the last mentioned item (it would probably be on top of a stack or in a variable which gets updated when an item is mentioned).

    If you are interested I wrote a blog post about another programming joke ( ).

    • LC

      Wow! Thank you very much. My programming experience is somewhat more limited (okay, much more limited); I had the vague sense that it might not be correct, but I didn’t know how to express that. Thank you for reading and for your insightful comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: