Created
October 9, 2013 20:03
-
-
Save Fluxx/6907393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# Needless local variables | |
############################################################################### | |
# bad | |
def foo(): | |
bar = 1 | |
return bar | |
# good | |
def foo(): | |
return 1 | |
# okay to assign to semantic locals if it helps readability when those locals | |
# are used in other method calls | |
def foo(): | |
dog = 'air bud' | |
age = CONSTANT_WITH_A_LONG_NAME['animals']['dogs']['air bud']['age'] | |
bithday(dog, age) | |
# as opposed to | |
def foo(): | |
birthday('air bud', CONSTANT_WITH_A_LONG_NAME['animals']['dogs']['air bud']['age']) | |
# or | |
def foo(): | |
birthday( | |
'air bud', | |
CONSTANT_WITH_A_LONG_NAME['animals']['dogs']['air bud']['age'] | |
) | |
# bad | |
def foo(): | |
bar = 1 | |
baz = qux(bar) | |
return baz | |
# good | |
def foo(): | |
return qux(1) | |
# bad | |
foo = bar.get('baz') | |
if foo: | |
foo.stuff() | |
# good | |
if bar.get('baz'): | |
bar['baz'].stuff() | |
############################################################################### | |
# Format internal imports? | |
############################################################################### | |
def foo(): | |
from bar import ( | |
baz, | |
buzz | |
) | |
return bar.stuff(buzz) | |
############################################################################### | |
# Docstrings okay one line if they're short. | |
############################################################################### | |
# okay | |
def foo(): | |
"""This is a short docstring""" | |
pass | |
# also okay? | |
def foo(): | |
""" | |
This is a short docstring | |
""" | |
pass | |
# not okay | |
def foo(): | |
"""Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo""" | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment