<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 9, 2016 at 12:36 PM, Barry Warsaw <span dir="ltr"><<a href="mailto:barry@python.org" target="_blank">barry@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On May 08, 2016, at 11:59 AM, Steven D'Aprano wrote:<br>
<br>
>I think it is preferable *not* to have boolean parameters at all.<br>
><br>
>I don't remember if this is Guido's name for it, but I remember him<br>
>expressing the guideline "No constant bool arguments". If you have an<br>
>argument which takes a bool, and is used solely to switch between two<br>
>different modes, and the caller will most likely call the function with<br>
>the argument as a constant known when writing the code (rather than<br>
>taking an expression or variable with value not known until runtime),<br>
>then it is usually better to split the function into two, one for<br>
>each mode.<br>
<br>
</span>I think Guido's point is stricter than that (but I don't want to put words in<br>
his mouth :). It's that a boolean flag argument shouldn't change the return<br>
type of the method. Flags can certainly change the behavior of a method and I<br>
think that's perfect fine.<br></blockquote><div><br></div><div>These are two different things. Any time the *value* of an argument affects the *type* of the return value there's a problem, not just for boolean parameters. E.g. open(..., "rb") vs. open(..., "r") is one of the worst offenders -- and "r" vs. "w" is another one for open()!<br><br></div><div>The thing Steven quotes is specific to boolean parameters and pretty much exactly what I would say about them.<br></div><div> </div></div>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>