Skip to content

Instantly share code, notes, and snippets.

@pydanny
Created July 8, 2020 23:17
Show Gist options
  • Save pydanny/6cf5f6344a59a655cf885dd86eefd5b2 to your computer and use it in GitHub Desktop.
Save pydanny/6cf5f6344a59a655cf885dd86eefd5b2 to your computer and use it in GitHub Desktop.
Which one is more legible?
def fun_function(name=None):
"""Find working ice cream promo"""
results = Promo.objects.active()
results = results.filter(
Q(name__startswith=name) |
Q(description__icontains=name)
)
results = results.exclude(status='melted')
results = results.select_related('flavors')
return results
def fun_function(name=None):
"""Find working ice cream promo"""
return (
Promo.objects.active()
.filter(
Q(name__startswith=name) |
Q(description__icontains=name)
)
.exclude(status='melted')
.select_related('flavors')
)
@mitcom
Copy link

mitcom commented Jul 9, 2020

The first one! It is easier to debug with breakpoint() (.set_trace()), debuggers or even "debug printing".

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