propter_hog [any, any]
link
fedilink
English
23d

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

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

@bl4kers@lemmy.ml
link
fedilink
English
166d

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

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

The Cuuuuube
link
fedilink
English
166d

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

@dev_null@lemmy.ml
link
fedilink
3
edit-2
4d

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.

@jerkface@lemmy.ca
link
fedilink
English
85d

Been programming since the 80s, ditto.

Ternary if?then:else

The Cuuuuube
link
fedilink
English
46d

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

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

why would you call it anything other than the ternary operator

@dev_null@lemmy.ml
link
fedilink
3
edit-2
4d

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.

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

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
3d

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

@dev_null@lemmy.ml
link
fedilink
2
edit-2
3d

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

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

I never heard it called the Elvis operator! Thanks!

It was called Elvis back when it was a smiley

Fonzie!
link
fedilink
276d

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

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

Elvis lip

Dwemthy (he/him)
link
fedilink
English
106d

Mfw I’m checking for null

cobysev
link
fedilink
English
36d

?:)

Holy shit

Kotlin user spotted

php too

…but we don’t talk about php

@Sleepzy@feddit.it
creator
link
fedilink
26d

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

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
2
edit-2
5d

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

Oh unfortunately these imaginary pains are those which hurt every day

Nobody’s assuming Groovy these days then 😂

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

Why the fuck is Groovy?

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

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

Create a post

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.
  • 1 user online
  • 153 users / day
  • 312 users / week
  • 700 users / month
  • 2.84K users / 6 months
  • 1 subscriber
  • 1.57K Posts
  • 34.8K Comments
  • Modlog