lemmy.4d2.org
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Sleepzy@feddit.it to Programmer Humor@lemmy.ml · 8 months ago

Elvis

feddit.it

message-square
16
link
fedilink
6

Elvis

feddit.it

Sleepzy@feddit.it to Programmer Humor@lemmy.ml · 8 months ago
message-square
16
link
fedilink
alert-triangle
You must log in or register to comment.
  • propter_hog [any, any]@hexbear.net
    link
    fedilink
    English
    arrow-up
    2
    ·
    8 months ago

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

  • bl4kers@lemmy.ml
    link
    fedilink
    English
    arrow-up
    0
    ·
    8 months ago

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

    • QuazarOmega@lemy.lol
      link
      fedilink
      arrow-up
      0
      ·
      8 months ago

      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
        0
        ·
        8 months ago

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

        • dev_null@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          8 months 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.

        • luciferofastora@lemmy.zip
          link
          fedilink
          arrow-up
          0
          ·
          8 months ago

          Ternary if?then:else

          • The Cuuuuube@beehaw.org
            link
            fedilink
            English
            arrow-up
            0
            ·
            8 months 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@lemy.lol
              link
              fedilink
              arrow-up
              1
              ·
              8 months 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

      • AVincentInSpace@pawb.social
        link
        fedilink
        English
        arrow-up
        0
        ·
        8 months ago

        why would you call it anything other than the ternary operator

        • dev_null@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          8 months 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@pawb.social
            link
            fedilink
            English
            arrow-up
            0
            ·
            8 months ago

            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
              2
              ·
              8 months ago

              It’s a shorthand for writing this:

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

              This is equivalent:

              variable = input ?: default
              
  • Blue_Morpho@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    I never heard it called the Elvis operator! Thanks!

    • The Ramen Dutchman@ttrpg.network
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago

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

  • deathmetal27@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    8 months ago

    Kotlin user spotted

    • QuazarOmega@lemy.lol
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago

      php too

      …but we don’t talk about php

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.

  • 376 users / day
  • 792 users / week
  • 2.77K users / month
  • 9.81K users / 6 months
  • 4 local subscribers
  • 37.2K subscribers
  • 817 Posts
  • 5.79K Comments
  • Modlog
  • mods:
  • cat_programmer@lemmy.ml
  • BE: 0.19.11
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org