Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
Sleepzy ( Sleepzy@feddit.it )  to Programmer Humor@lemmy.ml · 2 years ago

Elvis

feddit.it

message-square
15
link
fedilink
90

Elvis

feddit.it

Sleepzy ( Sleepzy@feddit.it )  to Programmer Humor@lemmy.ml · 2 years ago
message-square
15
link
fedilink
alert-triangle
You must log in or # to comment.
  • bl4kers ( bl4kers@lemmy.ml ) 
    link
    fedilink
    English
    arrow-up
    12
    ·
    2 years ago

    I don’t understand this. Small brained users rise up

    • QuazarOmega ( QuazarOmega@lemy.lol ) 
      link
      fedilink
      arrow-up
      12
      ·
      2 years ago

      On the left you have Elvis Presley, while on the right there’s the so-called Elvis operator

      • The Cuuuuube ( Cube6392@beehaw.org ) 
        link
        fedilink
        English
        arrow-up
        16
        ·
        2 years ago

        been programming since 2008. the fuck is an elvis operator?

        • Jerkface (any/all) ( jerkface@lemmy.ca ) 
          link
          fedilink
          English
          arrow-up
          8
          ·
          edit-2
          8 months ago

          Removed by mod

        • luciferofastora ( luciferofastora@lemmy.zip ) 
          link
          fedilink
          arrow-up
          4
          ·
          2 years ago

          Ternary if?then:else

          • The Cuuuuube ( Cube6392@beehaw.org ) 
            link
            fedilink
            English
            arrow-up
            4
            ·
            2 years ago

            gotacha. i’ve only ever heard them called ternaries. maybe i’m old. maybe i’m too young. definitely one of the two

            • QuazarOmega ( QuazarOmega@lemy.lol ) 
              link
              fedilink
              arrow-up
              8
              ·
              2 years ago

              It specifically refers to this shorthand ?: that works like this:

              $value = $thing_that_could_be_truthy ?: 'fallback value';
              
              # same as
              
              $value = $thing_that_could_be_truthy ? $thing_that_could_be_truthy : 'fallback value';
              

              The condition is also the value if it is truthy

        • dev_null ( dev_null@lemmy.ml ) 
          link
          fedilink
          arrow-up
          3
          ·
          2 years ago

          It’s a shorthand for writing this:

          variable = if (input != null) input else default
          

          This is equivalent:

          variable = input ?: default
          

          The answers confusing it with the ternary operator are wrong.

      • AVincentInSpace ( AVincentInSpace@pawb.social ) Banned from community
        link
        fedilink
        English
        arrow-up
        3
        ·
        2 years ago

        why would you call it anything other than the ternary operator

        • dev_null ( dev_null@lemmy.ml ) 
          link
          fedilink
          arrow-up
          3
          ·
          2 years ago

          Because it’s not one. Ternary operator is A ? B : C, Elvis operator is A ?: B. The same two characters are involved, but both the syntax and effect is different.

          • AVincentInSpace ( AVincentInSpace@pawb.social ) Banned from community
            link
            fedilink
            English
            arrow-up
            2
            ·
            2 years ago

            The second one isn’t valid syntax in any programming language I’m familiar with. What does it do?

            • dev_null ( dev_null@lemmy.ml ) 
              link
              fedilink
              arrow-up
              3
              ·
              2 years ago

              It’s a shorthand for writing this:

              variable = if (input != null) input else default
              

              This is equivalent:

              variable = input ?: default
              
              • AVincentInSpace ( AVincentInSpace@pawb.social ) Banned from community
                link
                fedilink
                English
                arrow-up
                2
                ·
                2 years ago

                Huh. Neat feature. That’s in C# I assume?

                • dev_null ( dev_null@lemmy.ml ) 
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  2 years ago

                  It’s in Kotlin and some other languages. C# has it but there it’s actually A ?? B.

        • QuazarOmega ( QuazarOmega@lemy.lol ) 
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          Read further down on my other comment to understand, it’s just how the operator looks

  • NicKoehler ( NicKoehler@feddit.it ) 
    link
    fedilink
    arrow-up
    2
    ·
    2 years ago

    Same

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 3 users / day
  • 221 users / week
  • 336 users / month
  • 1.83K users / 6 months
  • 871 local subscribers
  • 43.7K subscribers
  • 1.25K Posts
  • 10.3K Comments
  • Modlog
  • mods:
  • AgreeableLandscape ( AgreeableLandscape@lemmy.ml ) 
  • cat_programmer ( cat_programmer@lemmy.ml ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code