Hacker News new | ask | show | jobs
by saila 1538 days ago
I prefer code in this style too:

    if something:
        return something
    if something else:
        return something else
    return default
It's not applicable everywhere, but where it is, it seems tidier to me than the alternative:

    if something:
        return something
    elif something else:
        return something else
    else:
        return default
Edit: The article basically says the same thing. I just had a hard time parsing all that C at first.
2 comments

To me early returns and top level exceptions are nice to convey base cases, invariants, short cuts etc. nested branching to convey choice that is more closely related.

The former is often not possible (or idiomatic) in expression based languages however.

Agree. I always code that way (in non-functional languages).