Skip to content

Instantly share code, notes, and snippets.

@mcpower
Created January 16, 2015 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcpower/a868086375e983012a67 to your computer and use it in GitHub Desktop.
Save mcpower/a868086375e983012a67 to your computer and use it in GitHub Desktop.

Question to pythonistas out there: Is it acceptable to reduce indentation by doing:

if blah:
	# do stuff
	return
# do lots of other stuff

instead of:

if blah:
	# do stuff
else:
	# do lots of other stuff
@bobpoekert
Copy link

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

Copy link

ghost commented Jan 16, 2015

I 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.

Copy link

ghost commented Jan 16, 2015

i.e. I read the first as "if blah, stop what you would normally do and do this instead"

@auscompgeek
Copy link

👍 to @mispy, this is how I tend to write any of my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment