Åhall
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@Sleepzy@feddit.it to Programmer Humor@lemmy.ml • 1 year ago

Elvis

feddit.it

message-square
35
fedilink
154

Elvis

feddit.it

@Sleepzy@feddit.it to Programmer Humor@lemmy.ml • 1 year ago
message-square
35
fedilink
  • @AVincentInSpace@pawb.social
    link
    fedilink
    English
    3•1 year ago

    why would you call it anything other than the ternary operator

    • @dev_null@lemmy.ml
      link
      fedilink
      3•
      edit-2
      1 year 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
        2•1 year 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
          4•1 year ago

          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
            2•
            edit-2
            1 year ago

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

            • @dev_null@lemmy.ml
              link
              fedilink
              2•
              edit-2
              1 year ago

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

    • QuazarOmega
      link
      fedilink
      2•1 year ago

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

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.
  • 316 users / day
  • 836 users / week
  • 2.18K users / month
  • 7.24K users / 6 months
  • 39.4K subscribers
  • 1.91K Posts
  • 38.1K Comments
  • Modlog
  • mods:
  • @AgreeableLandscape@lemmy.ml
  • @cat_programmer@lemmy.ml
  • BE: 0.19.3
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org