Lemdro.id
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Sleepzy@feddit.it to Programmer Humor@lemmy.ml · 7 个月前

Elvis

feddit.it

message-square
34
fedilink
124

Elvis

feddit.it

Sleepzy@feddit.it to Programmer Humor@lemmy.ml · 7 个月前
message-square
34
fedilink
alert-triangle
You must log in or register to comment.
  • Blue_Morpho@lemmy.world
    link
    fedilink
    arrow-up
    40
    ·
    7 个月前

    I never heard it called the Elvis operator! Thanks!

    • The Ramen Dutchman@ttrpg.network
      link
      fedilink
      arrow-up
      25
      ·
      7 个月前

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

      • disguy_ovahea@lemmy.world
        link
        fedilink
        arrow-up
        21
        ·
        7 个月前

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

        Elvis lip

        • Dwemthy (he/him)
          link
          fedilink
          English
          arrow-up
          9
          ·
          7 个月前

          Mfw I’m checking for null

      • cobysev@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        arrow-down
        1
        ·
        7 个月前

        ?:)

    • MyNameIsRichard@lemmy.ml
      cake
      link
      fedilink
      arrow-up
      3
      ·
      7 个月前

      It was called Elvis back when it was a smiley

  • bl4kers@lemmy.ml
    link
    fedilink
    English
    arrow-up
    15
    ·
    7 个月前

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

    • QuazarOmega@lemy.lol
      link
      fedilink
      arrow-up
      13
      ·
      7 个月前

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

      • The Cuuuuube@beehaw.org
        link
        fedilink
        English
        arrow-up
        16
        ·
        7 个月前

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

        • Jerkface (any/all)@lemmy.ca
          link
          fedilink
          English
          arrow-up
          8
          ·
          7 个月前

          Been programming since the 80s, ditto.

        • dev_null@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          7 个月前

          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.

        • luciferofastora@lemmy.zip
          link
          fedilink
          arrow-up
          3
          ·
          7 个月前

          Ternary if?then:else

          • The Cuuuuube@beehaw.org
            link
            fedilink
            English
            arrow-up
            4
            ·
            7 个月前

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

            • QuazarOmega@lemy.lol
              link
              fedilink
              arrow-up
              8
              ·
              7 个月前

              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

      • AVincentInSpace@pawb.social
        link
        fedilink
        English
        arrow-up
        3
        ·
        7 个月前

        why would you call it anything other than the ternary operator

        • dev_null@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          7 个月前

          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@pawb.social
            link
            fedilink
            English
            arrow-up
            2
            ·
            7 个月前

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

            • dev_null@lemmy.ml
              link
              fedilink
              arrow-up
              4
              ·
              7 个月前

              It’s a shorthand for writing this:

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

              This is equivalent:

              variable = input ?: default
              
              • AVincentInSpace@pawb.social
                link
                fedilink
                English
                arrow-up
                2
                ·
                edit-2
                7 个月前

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

                • dev_null@lemmy.ml
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  edit-2
                  7 个月前

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

        • QuazarOmega@lemy.lol
          link
          fedilink
          arrow-up
          2
          ·
          7 个月前

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

  • deathmetal27@lemmy.world
    link
    fedilink
    arrow-up
    10
    ·
    7 个月前

    Kotlin user spotted

    • QuazarOmega@lemy.lol
      link
      fedilink
      arrow-up
      3
      ·
      7 个月前

      php too

      …but we don’t talk about php

      • Sleepzy@feddit.itOP
        link
        fedilink
        arrow-up
        2
        ·
        7 个月前

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

        • tetris11@lemmy.ml
          link
          fedilink
          arrow-up
          3
          ·
          7 个月前
          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.
          
          • fxdave@lemmy.ml
            link
            fedilink
            arrow-up
            2
            ·
            edit-2
            7 个月前

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

        • QuazarOmega@lemy.lol
          link
          fedilink
          arrow-up
          1
          ·
          7 个月前

          Oh unfortunately these imaginary pains are those which hurt every day

    • silasmariner@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      7 个月前

      Nobody’s assuming Groovy these days then 😂

      • chunkystyles@sopuli.xyz
        link
        fedilink
        English
        arrow-up
        2
        ·
        7 个月前

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

        Why the fuck is Groovy?

        • silasmariner@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          7 个月前

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

    • DeprecatedCompatV2@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      7 个月前

      (run { this@comment.parent?.apply { this.value === true } } == true) ?: if ((this@comment.value as? Boolean) != true) false else true

  • propter_hog [any, any]@hexbear.net
    link
    fedilink
    English
    arrow-up
    3
    ·
    7 个月前

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

    • Boomkop3@reddthat.com
      link
      fedilink
      arrow-up
      2
      ·
      7 个月前

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

  • NicKoehler@feddit.it
    link
    fedilink
    arrow-up
    2
    ·
    7 个月前

    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.

  • 271 users / day
  • 1.07K users / week
  • 3.59K users / month
  • 9.86K users / 6 months
  • 87 local subscribers
  • 36.2K subscribers
  • 1.73K Posts
  • 37.2K Comments
  • Modlog
  • mods:
  • cat_programmer@lemmy.ml
  • AgreeableLandscape@lemmy.ml
  • UI: 0.19.8
  • BE: 0.19.11
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org