[Python-ideas] bool.from_config_str()

Michael Selik michael.selik at gmail.com
Mon Jun 13 18:08:54 EDT 2016


On Mon, Jun 13, 2016 at 5:32 PM Bar Harel <bzvi7919 at gmail.com> wrote:

> The whole point of a good standard library is to prevent repetition.
>

Certain kinds of repetition, yes. Some code looks almost exactly the same,
but the slight differences make it hard to generalize as a function. In
those cases, it's better for the language to provide some simple tools that
can be composed to get the job done. In this case, we have ``value = config
in strings_that_mean_true`` which solves the category of problem quite
nicely.

The fact that the same concept exists twice even in the standard library
>

The repetition is that each case might have a different standard for what
strings are truthy and whether to raise an error if the string is an
unexpected value.

> tl;dr: My suggestion is a utility module containing many implemented recipes
> shortening many commonly used patterns. The only question is how to prevent
> over-extending it with lots of niche and less-used ones.
>
Some possible criteria for evaluating the benefit of a function/class:
- the code pattern it replaces is very common in stdlib and major projects
- the code pattern it replaces is a frequent source of bugs, even if rare
- the code pattern it replaces is hard to write, even if usually correct
- the code pattern it replaces is hard to read, even if rare and easy to
write

Sometimes copy-paste-tweak is OK.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160613/b79d1720/attachment.html>


More information about the Python-ideas mailing list