(Shamelessly stolen from reddit)

    • edinbruh@feddit.it
      link
      fedilink
      English
      arrow-up
      39
      ·
      2 days ago

      “Ternary operator” means “operator that takes three things”, like unary and binary operators take one and two things.

      In C there is an operator for conditional expressions (an ‘if’ that you can put inside expressions) and it looks like this condition ? trueBranch : falseBranch. It takes three expressions, so it’s a ternary operator.

      Except it’s the only ternary operator in C (and most languages, if they have one at all), so instead of calling it something like “conditional operator”, they just call it “the ternary operator”

    • MightBeFluffy@pawb.social
      link
      fedilink
      English
      arrow-up
      23
      ·
      edit-2
      2 days ago

      A ternary is a short hand to assign a value based on a true/false statement

      let a; if(isTtrue) a=2 else a=9

      Becomes

      let a = (isTrue) ? 2 : 9

      • TJA!@sh.itjust.works
        link
        fedilink
        arrow-up
        6
        ·
        edit-2
        2 days ago

        I really like the way kotlin is doing it. The readability of the first one and still a direct assignment.

        var a = if (isTrue) 2 else 9

        • mobotsar@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          1
          arrow-down
          1
          ·
          1 hour ago

          Well if you make me actually explain it, I’m going to sound like an asshole; the joke is so obvious and low-level and the type of humor so uninspired that I figure they must be a little… you know, dumb.

          • Lena@gregtech.euOP
            link
            fedilink
            English
            arrow-up
            2
            ·
            1 hour ago

            It’s not the best joke I’ve seen, but I wouldn’t call it dumb. To each their own, I guess. Jokes are subjective.