[Python-ideas] Boolean parameters guidelines

Barry Warsaw barry at python.org
Mon May 9 15:36:53 EDT 2016


On May 08, 2016, at 11:59 AM, Steven D'Aprano wrote:

>I think it is preferable *not* to have boolean parameters at all.
>
>I don't remember if this is Guido's name for it, but I remember him
>expressing the guideline "No constant bool arguments". If you have an
>argument which takes a bool, and is used solely to switch between two
>different modes, and the caller will most likely call the function with
>the argument as a constant known when writing the code (rather than
>taking an expression or variable with value not known until runtime),
>then it is usually better to split the function into two, one for
>each mode.

I think Guido's point is stricter than that (but I don't want to put words in
his mouth :).  It's that a boolean flag argument shouldn't change the return
type of the method.  Flags can certainly change the behavior of a method and I
think that's perfect fine.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160509/9d01b1ba/attachment-0001.sig>


More information about the Python-ideas mailing list