S
Steven D'Aprano
Why doesn't assemble_page properly handle the case where header, body,
and footer are all empty? That would let you eliminate the if. "Make
sure your code 'does nothing' gracefully" (Kernighan and Plauger).
You mean something like this?
def assemble_page(header, body, footer):
if header or body or footer:
do_lots_of_expensive_processing()
else:
do_nothing_gracefully()
Sure, why not?
Whatever way you do it, my point is that it is very useful to perform
branching tests on non-Boolean objects. Wherever you put the test, being
able to write:
if header or body or footer:
is a huge improvement over:
if (header != '') or (body != '') or (footer != ''):