15
lig1
8y

Yet again

If foo():
return True
else:
return False

Agrrr!!11

Comments
  • 2
    ...ouch
  • 0
    What's the problem?
  • 4
    @spl0 they could have just done

    return foo();
  • 4
    @c3ypt1c return bool(foo())
    Please:)
  • 3
    @c3ypt1c oh my god! That semicolon... Lol 😨
  • 2
    @c3ypt1c no it's not the same. We don't knoe that foo() returns Boolean.
  • 1
    If the if statement can evaluate foo() as a Boolean 9 times out of 10 you can assume that it is one.
  • 2
    @spl0 there is the only one way to do that. See my comment...
  • 0
    @Romulus10 ummm, depends on the language...
  • 2
    The syntax here is pythonic.
  • 0
    @Romulus10 well in python... for example, you could return 1 or 0. Thats not a boolean, but 'if' would still treat it as one....
  • 2
    In that case, this code could still be avoided. foo() could return directly to the target and would evaluate the same as if this code returned true or not.
  • 2
    Wish your code on my review guys...:)
  • 0
    @Romulus10 Yes but its an int. Just because if makes something of it, doesnt mean you can assume its a boolean!
  • 1
    Yeah, that assumption could probably end up not being the best practice. In most cases, though, I would probably leave this bit out.
  • 0
    From where I'm looking at it, leaving out the conditional will make the common case faster.
  • 0
    @Romulus10 I think lig's return bool(foo()) is probably the best unless we know foo() returns boolean, in which case just return foo()?
  • 0
    I wonder why (out of context of course) we couldn't skip the return statement and just call foo() from where we need it returned to.
  • 1
    @Romulus10 Because (in theory) we dont know whats before this code in the same function....
  • 0
    Yeah, that's why I said out of context. The fact that there are no arguments to foo() makes me think it should be safe but there's always the possibility.
  • 4
    @lig1 you can use semicolons in python... ;3 I do it out of habit...
  • 1
    @c3ypt1c moreover they is always a semicolon at the end of each line in Python. Even if you don't see it...
  • 0
    return foo();
  • 0
    @bboyoliva see above
Add Comment