Sleepzy ( Sleepzy@feddit.it ) to Programmer Humor@lemmy.ml · 2 years agoElvisfeddit.itimagemessage-square15linkfedilinkarrow-up190
arrow-up190imageElvisfeddit.itSleepzy ( Sleepzy@feddit.it ) to Programmer Humor@lemmy.ml · 2 years agomessage-square15linkfedilink
minus-squareThe Cuuuuube ( Cube6392@beehaw.org ) linkfedilinkEnglisharrow-up16·2 years agobeen programming since 2008. the fuck is an elvis operator?
minus-squareJerkface (any/all) ( jerkface@lemmy.ca ) linkfedilinkEnglisharrow-up8·edit-29 months agoRemoved by mod
minus-squareluciferofastora ( luciferofastora@lemmy.zip ) linkfedilinkarrow-up4·2 years agoTernary if?then:else
minus-squareThe Cuuuuube ( Cube6392@beehaw.org ) linkfedilinkEnglisharrow-up4·2 years agogotacha. i’ve only ever heard them called ternaries. maybe i’m old. maybe i’m too young. definitely one of the two
minus-squareQuazarOmega ( QuazarOmega@lemy.lol ) linkfedilinkarrow-up8·2 years agoIt 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
minus-squaredev_null ( dev_null@lemmy.ml ) linkfedilinkarrow-up3·2 years agoIt’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.
been programming since 2008. the fuck is an elvis operator?
Removed by mod
Ternary if?then:else
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
It’s a shorthand for writing this:
variable = if (input != null) input else defaultThis is equivalent:
variable = input ?: defaultThe answers confusing it with the ternary operator are wrong.