Thursday 17 February 2011

Needs debugging

A wife asks her husband, a software engineer: "Could you please go shopping for me and buy one carton of milk, and if they have eggs, get six." A short time later the husband comes back with six cartons of milk. The wife asks him, "Why the hell did you buy six cartons of milk?" He replied, "They had eggs."

Via reddit

6 comments:

Sergej said...

I don't get it. Is it because the wife ignores the return value of the AND?

Ironmistress said...

Two men are flying over Seattle on a small aircraft. Suddenly fog settles in, and they get lost.

In the midst there is a building, and a light in the window. The pilot flies by, and yells:

"Where are we?"

A voice replies: "You're in an airplane!"

The pilot takes a map, points on his finger and says: Now ten minutes flight on bearing 245 and we'll see a landing strip." They do it, and after ten minutes they see the approaching lights in the fog.

After they have landed, the other guy asks the pilot:

"How did you do it? How did you know we'd get to the strip?"

The pilot answers: "You remember what answer we got at that building?"

"Yup... he said we're in an airplane".

"Exactly. When you get answers like that, the building could not have been anything else but Microsoft product support. And it is precisely here on the map..."

Wunderbear said...

IronMistress:

I've heard the slightly different version of that joke. In the one I've heard, it was one pilot in a hot-air balloon, and he shouts to the man in the office building:

"Excuse me, can you tell me where I am?"

"You're in a hot air balloon hovering thirty feet above this field," comes the reply.

"You must be an engineer," says the balloonist.

"I do," says the man, "How did you know?"

"Well," says the balloonist, "Everything you told me is technically correct, but it's no use to anyone."

"You must be a manager," says the man.

"I am," says the balloonist, "How did you know?"

"Well," says the man, "You don't know where you are, you don't know where you're going, but you expect me to be able to help. You're in the same position you were before we met, but now it's my fault."

Ironmistress said...
This comment has been removed by the author.
Ironmistress said...

Sergej, no - the variable in the THEN sentence is undefined. The wife didn't specify that the husband needs to buy six eggs - the husband interpreted that if the IF condition is fulfilled, then the variable AmountMilkCartons gets the value 6. The wife didn't specify the variable AmountEggs in the THEN sentence.

The husband interpreted

IF (Eggs) AmountMilkCartons=6;

while it should have been

IF (Eggs) AmountEggs=6;

Sergej said...

You know, Ironmistress, this whole story has been bothering me. Here is what I'm seeing wrong.

I would translate the (poorly written) spec as:

(buy_milk(1) && if(eggs) buy_milk(6));

First of all, we do not know what, if anything, buy_milk() returns. If the compiler short-circuits the && (if specced in the language, etc.), the if() clause might simply never be reached. Second, buy_milk(1)+buy_milk(6) equals...? buy_milk(7), right? But the husband came back with only six cartons of milk. Perhaps he gave the seventh to a kitten he encountered on the way home, but this isn't stated in the story. Third, this kind of and-as-if lacks clarity. I certainly indulge in such assembly-isms, especially if I know that a (friendly) coworker is going to get his panties in a twist when he sees it, so I'll just make a note of it: once more, the AND is not used for its return value but for a language- and compiler-dependent side-effect. There's probably more wrong with this story; this is just off the top of my head.

I am still not certain which of these our host considers to constitute the humor of the anecdote. I would propose setting up a neural net or support vector machine, and training it on known instances of humor (and optionally, since Mr. Szondy is British, humour). This should get us to the bottom of the matter.