4 ms·
I prefer code in this style too: if something: return something if something else: return something else return default It's not a
by saila 5y 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.
- dgb23 5y agoTo 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.
- mbrodersen 5y agoAgree. I always code that way (in non-functional languages).