A women sent her kid that was into programming to the grocery store and told it:

“Please buy 1 bottle of milk if they have eggs buy 2”

The kid returned with just 2 bottles of milk. When it’s mom ask why it bought 2 bottles of milk, the kid said:

“Because they had eggs”

… Was the kid right?

  • Deebster@lemmyrs.org
    link
    fedilink
    English
    arrow-up
    10
    ·
    1 year ago

    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?

    • FeyterOPM
      link
      fedilink
      English
      arrow-up
      5
      ·
      1 year ago

      Yes the joke is definitely on human language and not on programming but I think programmer can be relate here. At least I feel this joke is made in every computer science ground class ever.

      • Navigate
        link
        fedilink
        English
        arrow-up
        4
        ·
        1 year ago

        I suppose it demonstrates the ambiguity of human language and need to formalize things for computers

    • jorge@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 year ago

      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”.

  • KYLXBN@iusearchlinux.fyi
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    1 year ago

    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.