halubilo.social
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@[email protected] to Programmer [email protected] • 2 years ago

Elvis

feddit.it

message-square
34
fedilink
152

Elvis

feddit.it

@[email protected] to Programmer [email protected] • 2 years ago
message-square
34
fedilink
alert-triangle
You must log in or register to comment.
  • @[email protected]
    link
    fedilink
    47•2 years ago

    I never heard it called the Elvis operator! Thanks!

    • The Ramen Dutchman
      link
      fedilink
      28•2 years ago

      It’s because if you turn it 90° to the right, it looks like Elvis’ hair with two eyes underneath!

      • @[email protected]
        link
        fedilink
        23•2 years ago

        I saw it the other way, with the question mark as the curl of his lip.

        Elvis lip

        • Dwemthy (he/him)
          link
          fedilink
          English
          10•2 years ago

          Mfw I’m checking for null

      • cobysev
        link
        fedilink
        English
        3•2 years ago

        ?:)

      • @[email protected]
        link
        fedilink
        1•2 years ago

        Holy shit

    • @[email protected]
      link
      fedilink
      5•2 years ago

      It was called Elvis back when it was a smiley

  • @[email protected]
    link
    fedilink
    English
    16•2 years ago

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

    • QuazarOmega
      link
      fedilink
      14•2 years ago

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

      • The Cuuuuube
        link
        fedilink
        English
        16•2 years ago

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

        • Jerkface (any/all)
          link
          fedilink
          English
          8•
          edit-2
          4 months ago

          Removed by mod

        • @[email protected]
          link
          fedilink
          4•2 years ago

          Ternary if?then:else

          • The Cuuuuube
            link
            fedilink
            English
            3•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
              link
              fedilink
              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

        • @[email protected]
          link
          fedilink
          3•
          edit-2
          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.

      • @[email protected]
        link
        fedilink
        English
        3•2 years ago

        why would you call it anything other than the ternary operator

        • @[email protected]
          link
          fedilink
          3•
          edit-2
          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.

          • @[email protected]
            link
            fedilink
            English
            2•2 years ago

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

            • @[email protected]
              link
              fedilink
              4•2 years ago

              It’s a shorthand for writing this:

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

              This is equivalent:

              variable = input ?: default
              
              • @[email protected]
                link
                fedilink
                English
                2•
                edit-2
                2 years ago

                Huh. Neat feature.

                • @[email protected]
                  link
                  fedilink
                  2•
                  edit-2
                  2 years ago

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

        • QuazarOmega
          link
          fedilink
          2•2 years ago

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

  • @[email protected]
    link
    fedilink
    13•2 years ago

    Kotlin user spotted

    • @[email protected]
      link
      fedilink
      3•
      edit-2
      2 years ago

      (run { [email protected]?.apply { this.value === true } } == true) ?: if (([email protected] as? Boolean) != true) false else true

    • QuazarOmega
      link
      fedilink
      3•2 years ago

      php too

      …but we don’t talk about php

      • @[email protected]OP
        link
        fedilink
        2•2 years ago

        php doesn’t exist, php can’t hurt you

        • @[email protected]
          link
          fedilink
          3•2 years ago
          You have absolutely nothing
          <?php
             well hello there again
          ?>
          to worry about. If PHP existed
          we would have sophisticated
          <?php
            I trust that life has
            been treating you well? 
          ?>
          methods of detecting it, and
          it would pose literally no
          <?php
            Don't open the door. It's me.
          ?>
          threat to anyone.
          
          • @[email protected]
            link
            fedilink
            2•
            edit-2
            2 years ago

            aah my favorite template engine, I have seen it so long ago

        • QuazarOmega
          link
          fedilink
          1•2 years ago

          Oh unfortunately these imaginary pains are those which hurt every day

    • @[email protected]
      link
      fedilink
      2•2 years ago

      Nobody’s assuming Groovy these days then 😂

      • @[email protected]
        link
        fedilink
        English
        2•2 years ago

        I’ve been working in Jenkins pipeline for a while now.

        Why the fuck is Groovy?

        • @[email protected]
          link
          fedilink
          1•2 years ago

          Well Grails didn’t stick around for long, but Gradle was only available with Groovy for many years before they added Kotlin support.

  • propter_hog [any, any]
    link
    fedilink
    English
    3•2 years ago

    I will never call this the “Elvis” operator. That’s as dumb as dog shit. It’s called the ternary operator.

    • Boomkop3
      link
      fedilink
      2•2 years ago

      I had to go into the comments to find that out. Is this like an old people thing?

  • @[email protected]
    link
    fedilink
    3•2 years ago

    Same

Programmer [email protected]

[email protected]

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: [email protected]

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.
  • 118 users / day
  • 397 users / week
  • 1.75K users / month
  • 5.36K users / 6 months
  • 42.4K subscribers
  • 2.01K Posts
  • 40.6K Comments
  • Modlog
  • mods:
  • @[email protected]
  • @[email protected]
  • BE: 0.19.3
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org