Skip to content

Instantly share code, notes, and snippets.

@Fluxx
Created October 9, 2013 20:03
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 Fluxx/6907393 to your computer and use it in GitHub Desktop.
Save Fluxx/6907393 to your computer and use it in GitHub Desktop.
###############################################################################
# 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