[OT-ish] Design principles: no bool arguments
steve+comp.lang.python at pearwood.info
Thu Aug 25 09:13:07 CEST 2011
One design principle often mentioned here (with a certain degree of
disagreement) is the idea that as a general rule, you shouldn't write
functions that take a bool argument to switch between two slightly
This is a principle often championed by the BDFL, Guido van Rossum.
it a name: the Boolean Trap.
No doubt there are counter arguments as well. The most obvious to me is if
the flag=True and flag=False functions share a lot of code, it is poor
practice to implement them as two functions with two copies of almost
My solution to this is a technical violation of the "Avoid Boolean Trap"
principle, but only in a private function:
def _spam(arg, flag):
 This is the Internet. There's *always* a certain amount of disagreement.
More information about the Python-list