Hacker News new | ask | show | jobs
by pieguy 4776 days ago
And what's the alternative for if(A && B){ x(); }else{ y(); }? Seems very easy to shoot yourself in the foot with this approach.
2 comments

Well, you could

    if (one) {
    if (two)
    if (three)
    if (soon) {
        stuff
    }} else {
        else stuff
    }
Personally, I think I won't have any trouble reading that, but I have noticed I'm somewhat more tolerant than others in this regard. Though I am more OCD than others in other ways.
That doesn't what he's talking about, though. Your else will run anytime `one` is false, not when `one && two && three && soon` is false.
But it's still not the equivalent of: if (one && two && three && soon) {stuff} else {stuff} which I assume the GP meant.
Here, the x() and y() are assignments, so it's easy:

    ret = 0; //y()
    if (A)
    if (B)
        ret = 1; //x()
If the else statement is more involved, it gets difficult.