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
-
-
If you want to return a Boolean and the condition might return 0, this is actually useful. But I think this is mainly a PHP use-case...
-
how about this:
int result = foo();
if result
bar();
else
fubar();
/** i changed to this **/
foo() && bar() || fubar(); // oh no that's too complicated
foo() ? bar() : fubar(); // that's ugly
... these people deserve death by a thousand cuts -
Pointer32378yBehold! The best option that exists:
if (condition != true)
return !condition;
else if (!condition == false)
return !condition;
Truth table:
Condition Output
false | true
true | false -
cors24398yyou could as well use ternary operator in c++ as:
return (value == true ? true : false)
this would be more efficient code :D -
@davide
Sure, didn't say it's the best or most elegant way to do it. Just wanted to point out that it might actually make sense depending on language and context
Related Rants
If (condition)
return true
else
return false
😂😂😂
undefined
wk47