[Python-ideas] Revisiting dedicated overloadable boolean operators

Todd toddrjen at gmail.com
Sat Aug 4 00:00:05 EDT 2018


On Fri, Aug 3, 2018 at 6:05 PM, Benedikt Werner <1benediktwerner at gmail.com>
wrote:

> There was a proposal to allow overloading boolean operators in Pep-335
>> [2], but that PEP was rejected for a variety of very good reasons.  I think
>> none of those reasons (besides the conversation fizzling out) apply to my
>> proposal.
>>
> Maybe I am missing something, but I don't really see how this idea solves
> the problems that lead to PEP 335 getting rejected. As far as I understand
> it the main reason for the rejection was that this would decrease
> performance for all boolean operations which are extremely common where as
> the need for overriding these operators is rather rare. (See the rejection
> email here: https://mail.python.org/pipermail/python-dev/2012-March/
> 117510.html)
>
> As I see it this proposal only proposes a different syntax and doesn't
> solve this problem.
>
> The only real solution for this would be a new set of operators but I
> agree with Chris that overriding the bitwise operators is good enough for
> most cases and a new set of operators really is a bit over the top just for
> this. I especially dislike using || and && as they are prominently used in
> other programming languages and this would be extremely confusing for
> newcomers from those languages. Also if the syntax isn't clear and consice
> I feel it doesn't really add any value as the main point of operator
> overloading is to make code easy to read and understand. This really only
> would be the case if we could overload the boolean operators. Otherweise I
> think using a function or overloading the bitwise ops is the best solution.
>
>
The proposal is for new operators.  The operators would be "bNOT", "bAND",
"bOR", and "bXOR".  They would be completely independent of the existing
"not", "and", and "or" operators, operating purely on boolean values.  It
would be possible to overload these operators.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180804/2553e923/attachment.html>


More information about the Python-ideas mailing list