Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
olback107945yRust does not have ternary operators either. You can however do this:
@highlight
let y = match x {
true => 5,
false => 42
} ; -
The ternary operator IS usually the Elvis operator, and it is only necessary in languages where "if" is a statement and not an expression. That's because a statement doesn't return a value while an expression does.
-
@Fast-Nop meh. Sounds good, but i never gave a damn about if returning something. Most of the time one single if(){...} will have many lines of code .
If i wanted a conditional to return something, ternary was my weapon of choice. And ternary on average was less used in the code than actual if else, and everything was quite sorted out:
- wanna run multiple lines on a single condition? If else.
- Wanna run 1 line for 1 condition? Ternary.
- Wanna run 1 line of code for multiple conditions? Switch cases -
@StopWastingTime The ternary was your weapon of choice BECAUSE "if" didn't return anything, and that's BECAUSE it was a statement.
In a language where "if" is instead an expression, the ternary operator would be a pointless redundancy, and axing these is good design.
In that scenario, the ternary is a workaround where the original problem that lead to the workaround doesn't exist anymore. -
@highlight
Ughh, pattern matching has gotten so good. I love living in the future.
Related Rants
-
linuxxx32*client calls in* Me: good morning, how can I help you? Client: my ip is blocked, could you unblock it for m...
-
DRSDavidSoft28Found this in our codebase, apparently one of my co-workers had written this
-
linuxxx23*client calls* "hello, we forgot the password to our WiFi router. Could you reset that for us?" 😐😶😮...
i can never understand the theme behind kotlin.
THEY DON'T HAVE A FUCKING TERNARY OPERATOR!!![?:]
Like before realizing this, i thought yeah jetbrains has decided to make android development a privileged hobby and non beginner friendly , so its now creating an encoding like language, in the false theme of " reducing code size"
But now they remove WORLDWIDE KNOWN, OPTIMIZED , EASY TO READ AND USE AND UNDERSTAND FEATURE of ternary operator and replacing it with less powerful but same looking elvis operator.( and stating that using if else for that is a better option)
Like why? if your goal is to make a shitty encoding language that makes everything shorter and most of the things optional, why remove the already efficient if else encoder?
God knows when this stupid language is going to stop my brain from getting blasted
rant
if-else
elvis
ternary
kotlin
?:
wtf