The child should have bought 3 bottles of milk.
Programmer Humor
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
You're hired, when can you start?
I always think this joke is more of a linguistics/grammar joke than programming. The kid resolves the ambiguity in the ellipsis incorrectly, but why is this a programmer joke?
I heard this joke in Spanish, but the meaning is a bit different. Eggs is a colloquial/slang term for testicles (like balls in English), so "if you have eggs" means "if you dare".
I love having a joke that works in two languages but for different reasons.
For a serious reoly, I think the expression "If they have eggs, buy two" is redundant. If they didn't have eggs, the kid just can't and won't buy any eggs.
I think the proper command would be, "Please buy 1 bottle of milk and two eggs." That way, the kid won't be confused and it's still a proper valid command.
Unfortunately though, the sentence is ambiguous even to non-programmers. It is unknown whether the if condition applies to
- buying two eggs (buy two eggs)
- buying two bottles of milk (buy two bottles instead)
- or buying a bottle of milk (buy another bottle)
Simply because they didn't specify which to buy.
For a non-serious reply,
cart.add(supermarket.takeProduct(ProductType.milk, 1));
if (supermarket.getProduct(type: ProductType.eggs).length > 0) {
cart.add(supermarket.takeProduct(Product type.milk, 2));
}
cart.checkout();
The kid should have bought a total of 3 bottles.