Programming Joke

A wife asks her husband, a programmer, “Could you please go shopping for me and buy one carton of milk, and if they have eggs, get 6?”

A short time later the husband comes back with 6 cartons of milk and his wife asks, “Why did you buy 6 cartons of milk?”

He replies, “They had eggs.”

I find this to be the most unfunny programming joke in the dozens of programming jokes I’ve heard since I started programming. It’s even worse than the “Why is Halloween the same as Christmas?” joke – at least that one’s a cute coincidence for number systems.

At first glance, it looks like a straightforward joke: a direct translation of the statement make the husband buy six cartons of milk:

milk_to_be_bought = 1
if they_have_eggs
  milk_to_be_bought = 6
end
buy_cartons_of_milk(milk_to_be_bought)

But that’s not even a direct translation! A direct translation would be:

buy_one_carton_of_milk
if they_have_eggs
  buy_six_cartons_of_milk
end

This results in the husband buying 7 cartons of milk!

But no, the conversion from command to program is still incorrect. Here’s a much more direct translation:

buy_one_carton_of_milk
if they_have_eggs
  get_six
end

get_six what?

That’s the thing: no self respecting programmer would do what the husband did in the joke. A joke computer scientist would not do anything until the linguistic ambiguity is resolved, while a joke software engineer would also refuse to do anything until the unclear requirements are clarified, documented, and signed off.

Now if the joke went like “A wife asks her husband, who just started Codecademy last night…“, it would probably work.

11 thoughts on “Programming Joke”

  1. i had the same question in mind too.. the requirements were not clear enough to create a functional code. Though by using some logic and assumption that the wife means 6 cartons of milk, the joke would still be wrong since it should 7 and not just 6

    1. Anymore than that and it will be very boring.

      I’d rather be bored than see non-programmers try to look witty with this stupid “joke”.

  2. Actually I think you have a logic error in the statement about 7… no where in there does it say anything about adding 6 to the initial.

    1. And no where in there does it say anything about replacing the original command with the second.

      Actually it uses “and” in the middle so it’s imperative flow: if you buy 1 of something, then in the next command you buy 6 of something, how many did you buy all in all?

  3. I GOOGLED THIS JOKE JUST TO FIND OTHER PEOPLE WHO THINK THE SAME. THANK TYOU BRU IDASORYY FOR CAPS LOCK. People who claim this is a good joke obviously are just wannabe programmers, if that’s even a thing.

    1. That it? The most cliched comeback to calling something unfunny?

      You know what aren’t fun at parties? Posers. Tell this to a group of experienced (paid/working) programmers at a party and they’d only laugh either because (a) they don’t want to tell you how stupid your joke is, or (b) they’re stupid TDWTF-level programmers who haven’t been adequately punished for not clearing up ambiguities in spec.

    1. …which is exactly the first code snippet above, but written with variable names more in line of what a working software developer should be using.

Leave a Reply