Comment

Comment by userbinator

When I can't return early, I find that the && operator, because of its short-circuit evaluation, is extremely useful for writing chains of "everything before must successfully execute" without the labourious series of "if/else ladders" or deep nesting that would otherwise be needed. Compare:

    success = doOneThing() 
           && doSecondThing()
           && doThirdThing()
           ...
           && doLastThing();
and the more common "traditional" way:

    success = doOneThing();
    if(success)
    {
        success = doSecondThing();
    }
    if(success)
    {
        success = doThirdThing();
    }
    ...
    if(success)
    {
        success = doLastThing();
    }
parent userbinator 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton