+1 on Steven D'Aprano's suggestion (And thus Nick's too).

I have seen way too many complicated functions with lots of booleans that create an ugly 20 lines function call.
I agree that splitting into 2 if possible is a good idea, and in the cases it's not, requesting keyword only arguments
is a great solution.

I do think though that in case of many possible options, using IntEnums and OR operators is the preferable method,
unlike open() that uses a string, but that's again just a private opinion.

Huge +1.


On Mon, May 9, 2016 at 8:58 PM Chris Barker <chris.barker@noaa.gov> wrote:
On Sun, May 8, 2016 at 6:08 AM, Eric V. Smith <eric@trueblade.com> wrote:

Wouldn't that be "for every (or almost every) call-site"?

"most call sites" would be fine. The common use case matters, it's not that hard to conditionally call a different function, as long as that's the uncommon use-case.

The other key here is that even if a boolean flag does essentially select between two different function, there are times where there is more than one such boolean flag for a single function, so you end up with 2**n "different" functions -- in this case, probably better to just use the flags and have one calling point.

-CHB



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/