Question to pythonistas out there: Is it acceptable to reduce indentation by doing:
if blah:
# do stuff
return
# do lots of other stuffinstead of:
if blah:
# do stuff
else:
# do lots of other stuffQuestion to pythonistas out there: Is it acceptable to reduce indentation by doing:
if blah:
# do stuff
return
# do lots of other stuffinstead of:
if blah:
# do stuff
else:
# do lots of other stuffI generally use them to convey slightly different things. The former indicates that "blah" is an unusual case that should be handled separately, while the rest of the code is a more common path. The latter suggests more expected/constrained variation.
i.e. I read the first as "if blah, stop what you would normally do and do this instead"
👍 to @mispy, this is how I tend to write any of my code.
My personal opinion, which others may disagree with: the first version is fine if and only if it’s at the top of the function