98
davide
2y

If (condition)
return true
else
return false
😂😂😂

Comments
  • 1
    I do not see a problem here.
  • 5
    @Cyanite It's better to use this:
    return condition
    than that longer version.
  • 0
    @Csaki Ohhhhhhh.... I see now.
  • 0
    Im so guilty of this
  • 0
    But why?
  • 0
    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...
  • 7
    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
  • 4
    In JS, return !!condition; works like a clock
  • 0
    I see this soon many times :'(
  • 2
    @nordlicht
    It's better
    return condition == true
  • 3
    Behold! The best option that exists:

    if (condition != true)
    return !condition;
    else if (!condition == false)
    return !condition;

    Truth table:

    Condition Output
    false | true
    true | false
  • 1
    you could as well use ternary operator in c++ as:

    return (value == true ? true : false)

    this would be more efficient code :D
  • 0
    runs away 😲
  • 2
    Return condition;

    or at least

    If (condition)
    Return true
    Return false
  • 0
    I mean. I see it, then I don't see it.
  • 0
    @cankarales Thank you!
  • 1
    @apex IT BURNS!!!!
  • 0
    return condition ? true : false;
  • 0
    @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
  • 0
    @pttsky just saw this rant I was going to point it out if u didn't. Use it all the time. Love how terse it is.
  • 0
    return !!(condition)
Your Job Suck?
Get a Better Job
Add Comment