This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients Roee Nizan, brett.cannon, serhiy.storchaka, steven.daprano, vstinner, wolma
Date 2019-08-21.11:10:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <20190821111040.GU16011@ando.pearwood.info>
In-reply-to <1566384662.12.0.729036973025.issue30413@roundup.psfhosted.org>
Content
On Wed, Aug 21, 2019 at 10:51:02AM +0000, STINNER Victor wrote:

> Rather than adding a new function, why not adding a parameter like 
> sort(key=func, reverse=True)? Something like fnmatch.filterfalse(pat, 
> invert=True)?

Guido argues that as a general rule of thumb, we should avoid "constant 
bool parameters" and prefer seperate functions. For example, we have

- re.search and re.match, not re.search(start=True)

- str.find and str.rfind, not str.find(end=False)

If we typically call the function with a bool constant:

    filter(pat, invert=True)

rather than a variable or expression

    filter(pat, invert=condition or default)

that's a hint that the two cases probably should be seperate functions.

Martin Fowler agrees:

https://martinfowler.com/bliki/FlagArgument.html

as does Raymond Chen:

https://devblogs.microsoft.com/oldnewthing/20060828-18/?p=29953

(Of course there are cases where it is impractical to avoid bool flags 
-- if a function would otherwise take four flags, we would need sixteen 
functions! -- or there may be other reasons why we might go against that 
design rule.)
History
Date User Action Args
2019-08-21 11:10:49steven.dapranosetrecipients: + steven.daprano, brett.cannon, vstinner, serhiy.storchaka, wolma, Roee Nizan
2019-08-21 11:10:49steven.dapranolinkissue30413 messages
2019-08-21 11:10:49steven.dapranocreate