• juliebean@lemm.ee
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    what would be the alternative? to always execute if the condition is true, but sometimes execute it even when false, for funsies?

    • bstix@feddit.dk
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      The “only” part implies exclusivity, which may be false, because other things might run the code anyway.

      IF “I can see the sun” THEN “It’s day.”

      Nothing wrong about that. However if we make it exclusive:

      IF AND ONLY IF “I can see the sun” THEN “It’s day.”

      That’s obviously wrong. I can actually not keep the day away by sitting with closed eyes in my mothers basement with the curtains shut.

      “Only if” might make sense in a legal contract, but there’s no way a piece of code can stop other pieces of code from calling the same functions.

      • adj16@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 year ago

        But that’s not how if statements in code work. So what you’ve said isn’t wrong, but the premise of this meme is completely off

        • bstix@feddit.dk
          link
          fedilink
          English
          arrow-up
          0
          ·
          edit-2
          1 year ago

          Yes sure. Code is logical stepwise. By including the “only if” it implies that other stuff is taken into account, which it isn’t at that moment in code.

          I mean, I don’t need to extend the implications of an IF statement. It already does exactly what it says.

          Anyway fuzzy logic does exist for people who want “sometimes if”. It’s useful in certain cases. I’ve only ever considered it in music production, where things very often get to the point of complexity where it makes a (sometimes) useful difference.

  • Steve Dice@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    No, they’re not.

    Let’s assume they are. Let funky function be defined as:

    int funky() {
        a=0
        b=1
        if ( a==1 ) {
            b=1
        }
        return(a)
    }
    

    Since a==1 if, and only if, b=1, in particular a==1 if b=1. We have b=1, therefore a==1. It follows funky will always return 1 but… it doesn’t. QED.

  • raoul@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    The boolean operator ‘If and only if’ do not have a relation with the program instruction ‘if’.

    The programatic ‘if’ is a jump, not a boolean operator. It do not have truth table.

    In logic:, if and iff can be seen like functions taking two booleans and returning a boolean

    • ‘if a then b’ (noted a -> b): return true if a is false or b is true. Example: ‘if I eat pizza then I fart’ This is true even if I fart all the time (if b is true, we do not care about the value of a) as long as I fart when eating pizza (if a is true, b must be also true)

    • ‘a <-> b’ is equivalent to ‘a -> b and b -> a’: the two should be true at the same time. I can only fart will eating pizza and cannot fart otherwise.