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
Search - "ternary operator"
-
Kotlin: I don't have ternary operator, it's bad for readability
Swift: I removed ++ and --, cause they are old fashioned
Dart: *screams*23 -
Why is the ternary operator such a hated thing? I constantly hear people saying it's less readable, confusing, etc.
I think it's a beautiful, useful, and important operator and I use it constantly wherever readability won't be much affected.
How can you justify a repetitive if/else structure over a ternary, given that you're sure you're not going to put anything else in the ifs?
Whatever happened to DRY?
Whatever happened to KISS?
If those guidelines are what you code by, what's the excuse not to use it?
Because you can't read it as well? Familiarity breeds comprehension and legibility, my dudes.15 -
Saw a lot of posts on social media recently where people highlight a specific quote/sentence from a book/ebook and post it's picture online.
It only I could do the same with the killer ass functions I wrote, or the fifth degree nested ternary operator line of code I wrote that makes the whole component work and is the most beautiful thing I've ever seen. -
Came across a method in the code base that returns a boolean.
It uses a ternary operator which returns true if the result is true and false.. you guessed it... if the result is false.
WHY NOT JUST RETURN THE FUCKING RESULT!!!
What. The. F#%#....2 -
I don't really get it why my co-male dev does not like ternary operator as a shorthand operator for if/else statements.15
-
Oh! no There is more than 10 level of nesting conditions in if else statements. I can not refactor it but It needs to add more nest there. I will only add switch statements or ternary operator for the deeper nesting conditions.4
-
Spent like 24h trying to figure out why the system does not work. It turns out I forgot to put ternary operator into parentheses. :///10
-
According to people here, ternary operators. I don't care what I'm doing, if I can use a ternary operator instead of an if, get ready for it!
I guess implicit brackets on conditionals and for loops if it's a single line. Anything that saves me typing boilerplate, but it's still readable, I'm gonna do it.1 -
What's your opinion on functional shortcuts and 'hacks' in many languages, like map/reduce/filter, ternary operator, lambdas,inner/anonymous classes?
Imo they can make development faster and more efficent but they make the code very unreadable, especially if someone else has to read it, Therefore I try to use them only when it's appropriate. My dev friends use them too much and it makes reading their code a hellish experience, especially in Javascript with Rx.3 -
so
?. <- optional chaining
?? <- nullish coalescing
? <- conditional/ternary operator
dunno why, I can't seem to remember optional chaining off the top of my head.8 -
The most excited I was about my code was when I shrunk a bunch of easy if-else statements to a couple of lines using ternary operator. It wasn't groud breaking but it was the first time I felt like a programmer writing nice code.
-
People hate on Python a lot. I just used the Python ternary operator for the first time. I found it easier to read than the C++ ternary operator:
0 if i==0 else 2 if i==segmentMax-1 else 1
vs
i==0 ? 0 : i==segmentMax-1 ? 2 : 1
I think Python did a good job in this case.18 -
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 blasted11