She just doesn’t understand!

While debugging a problem with some C code, I came across this laugh-out-loud funny (in a very geeky way) explanation of one of the evils of the short-circuit evaluation of logical expressions.

Stick with it, it’s really quite funny.


Mom (thinks in VB-ish):
If kid.CleanTheDishes() And kid.DoHomework() Then
    we.GoToMovie you.PickMovie()
End If

Child (thinks in C-ish)
if (me->CleanTheDishes() && me->DoHomework())
{    we->GoToMovie(me->PickMovie());
} else
{    me->fool_around();
}

boolean CleanTheDishes()
{    ...
    if (kitchen->Inventory("soap") SoapNeeded())
    {    shoppingList->add("soap");
        todo->add("Clean The Dishes");
        return false;
    }
    ...
}

Mom:
If Todo.Contains("Clean The Dishes") Then
    Ask kid, "why didn't you clean the dishes" 
End If

Child:
mom->show(kitchen->Inventory);
mom->show(shoppingList);

Mom:
If kid.Explanation.IsSatisfactory() Then
    Pat kid
End If

If Not kid.Homework.IsDone Then
    Ask kid, "why didn't you do your homework"
End If

Child:
if (mom->makes_no_sense())
{    mom->explain("Because && short-circuits");
    mom->explain("See, doing homework is just a side effect");
    mom->explain("I already knew that !we->GoToMovie(...)");
}

Mom:
kid.GetSupper = False
kid.SendToRoom

Child:
while (me->in_room)
{    me->grumble("She just doesn't understand...");
}

I can see myself asking Nicholas whether he’s using .NET or C-style evaluation one day… (g)

Leave a comment