[Python-ideas] bool.from_config_str()
Bar Harel
bzvi7919 at gmail.com
Mon Jun 13 18:34:06 EDT 2016
Thanks for the feedback. I like your criteria suggestions btw.
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.
>
Well, both configparser and strtobool evaluate the same strings as True and
False, and both raise an exception but I see what you're saying.
I personally feel that a new utility module has space much like itertool's
common recipes and their function "equivalent" explanations. Heck, even
itertool itself is basically a utility module, but another option is
creating a wiki page similar to PerformanceTips
<https://wiki.python.org/moin/PythonSpeed/PerformanceTips> in
wiki.python.org. It won't require even a single line of code and being
marked as "suggested guidelines" from the python community may be highly
beneficial.
What do you think of that? :-)
On Tue, Jun 14, 2016 at 1:09 AM Michael Selik <michael.selik at gmail.com>
wrote:
> 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/4f072832/attachment.html>
More information about the Python-ideas
mailing list