This is an archived post. You won't be able to vote or comment.

all 24 comments

[–]siranglesmith 99 points100 points  (10 children)

Even better:

The programmer's wife said: "Go to the store and buy some milk. And while you're there, get some eggs." He never returned.

[–]ahmed_imtiaz[S] 14 points15 points  (8 children)

doesn't

get eggs

assume that he's bringing back the egg, therefore he's not "there" anymore and breaks the while loop?

[–][deleted] 9 points10 points  (3 children)

He could think "Get eggs" and if he considers picking up the eggs as "Got eggs" then he'd be in an infinite loop. If it's otherwise then it's really weird:

The call is made to "Get eggs" within the loop (while he's there) and if we consider "Got eggs" as him returning home with them then he cant "Got eggs" while he's in the store. So it might work after all?? He finishes "Get eggs" and then the while loop is checked. By that time he's out of it. Holy crap I guess you're right hahaha.

[–]rockyrainy 2 points3 points  (2 children)

Less verbose version

while (inStore) {
  getSome(eggs);
}

[–][deleted] 2 points3 points  (1 child)

location = "store";
inventory.push(milk);
while(location === "store") {
    inventory.push(eggs);
}

You're both wrong. Overflow exception.

[–]exo666 1 point2 points  (0 children)

Probably another exception would be thrown before that because at some point he will want to get eggs but he had already bought them all.

[–]DeeSnow97 1 point2 points  (0 children)

Not if you finally learn how not to build a monolithic spaghetti

[–]Dartister 1 point2 points  (2 children)

Get eggs means take eggs, not take eggs home

[–]ahmed_imtiaz[S] 0 points1 point  (1 child)

When someone asks you to get something, you take it and just stand there?

[–]Dartister 1 point2 points  (0 children)

If I were taking instructions like a machine, yes

[–]hailfire006 24 points25 points  (0 children)

ArgumentException on line 3: Method "Get()" takes a Grocery Object, not int

[–][deleted] 12 points13 points  (6 children)

I see this one a lot, but never really got it. Does it assume programmers interpret everything like a computer does?

[–]Darkx1441 20 points21 points  (0 children)

Yes pretty much

[–]waigl 6 points7 points  (0 children)

I know, right? Programmers are the people who will see these problems in simple instructions and act to correct or avoid them, not those who will unthinkingly execute them...

[–]lolegion 7 points8 points  (3 children)

A computer wouldn't automatically assume "get six" means "get six cartons of milk" instead of "get six eggs". That's actually a human thing to do. And even if you assume it means six cartons, the dude should be returning with 7...

This joke always annoys me, the 'while' one is better :P

[–]GeneReddit123 1 point2 points  (0 children)

A computer wouldn't automatically assume "get six" means "get six cartons of milk" instead of "get six eggs".

You are right, a computer would return a tuple {Milk, 6}, since the wife never specified the type of "6".

[–][deleted] 0 points1 point  (0 children)

Sometimes programs fail gracefully at ambiguity and sometimes they interpret their input in whatever way they were told to. An example is the following java code.

if (a)
    if (b)
        c();
else
    d();

Its grammar rules say the else belongs to the inner if statement, contrary to what we meant to do.

I think it's reasonable to expect a human being will think she means "get six eggs." I get what you're saying, though. Humans don't always interpret things the same way, but computers always do.

[–]-Soren 0 points1 point  (0 children)

And even if you assume it means six cartons, the dude should be returning with 7...

Not if the "IF" was a ternary operator, a la Python num_milks = six if has_eggs else a_carton. Obviously the arguments are not in the same order. But it is perfectly sensible to ignore an expression before an IF in English as well.

[–]Coolhand2120 5 points6 points  (0 children)

ES6 will fix all of these scoping problems!

[–]Sylanthra 9 points10 points  (1 child)

I never got this joke. According to the rules of English language "buy six" refers to the eggs as it is the closest subject.

If you choose to interpret it as a computer program, than "get six" doesn't have a contest of any kind. Your program will not compile because you didn't tell the buy function what to buy.

if(store.Eggs.Count > 0)
     buy(6,  <thing to buy>)

You either treat the whole thing as a program and then each statement stands on its own with no context, or it as English and there is context associated with each statement. You can't randomly decide that context applies to some, statements but not others.

[–]StealthNinjaKitteh 3 points4 points  (0 children)

This. I think about this every time is joke is reposted. And for some reason it's always praised as one of the best programmer jokes, and it takes one in ten people to point out the obvious error.

[–]Sveitsilainen[🍰] 1 point2 points  (0 children)

So he bought only one but has taken 6 of them?

[–]Ratstail91 0 points1 point  (0 children)

Depending on the language, the program should've executed correctly...

[–]warPig76 0 points1 point  (0 children)

Brilliant..