Hacker News new | past | comments | ask | show | jobs | submit login

How about this:

   return condition;



I'm certain he was using True and False as arbitrary values. It's a shame his point was missed. Please try to focus on his actual argument.


I'm not so convinced that it's not a fundamental thing.

Maybe someone wants to post a 'better' example and we'll see where it goes?


How about:

    if (condition())
        return 10;
    return 20;
versus

    val = 20;
    if (condition())
         val = 10;
    return val;


Well:

    val = condition() ? 20 : 10;
    return val;


Did you invert the logic of the parent post on purpose?


Or even:

    return condition() ? 10 : 20;


Yeah, that's definitely a more reasonable way to implement the above example. I didn't put much thought into the specifics of the code, since the specifics have nothing to do with what point I was making. I was responding to a question about multiple returns; the simple example was supposed to illustrate my opinion on multiple returns, not how to return a boolean value given a boolean condition.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: