[Python-ideas] [Python-ideos] Dedicated overloadable boolean operators

Chris Barker - NOAA Federal chris.barker at noaa.gov
Mon Nov 23 20:38:38 EST 2015


> I honestly think the added confusion makes it a non-starter.

Coming from my experience from the Numpy world, the fact that you get
"rich comparisons" for most what seem like Boolean operators, but not
for and and or is very confusing to newbies.

Much of the time, you can use the bitwise operators, as you often have
done a comparison first :

(A < x) & (A > y)

But it's kind of a coincidence that it works, so it only makes thing
more confusing for newbies. Bitwise operators really are kind of
obscure these days.

Explaining that you use ".and." Instead of " and" would be a much
lighter lift than getting into the whole explanation for why we can't
overload "and".

-CHB

I think first we decide it is or isn't a good idea, and then decide
how to spell it, but .and. and .or. kind of appeal to me.





> It's also
> confusing that in other languages that have && and ||, they are
> shortcut operators, but the proposed operators here won't be. And the
> real question isn't "when to use & vs. &&", it's "when to use 'and'
> vs. &&".
>
>> On Mon, Nov 23, 2015 at 4:08 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>> On Tue, Nov 24, 2015 at 10:49 AM, Jelte Fennema <me at jeltef.nl> wrote:
>>> As for the PEP, I have no problem writing one if this is accepted as a
>>> useful addition. Also any suggestions and critiques are very welcome of
>>> course.
>>
>> I think it's reasonable, except for the potential confusion of having
>> *three* "and" operators. The one with the word is never going to
>> change - its semantics demand that it not be overridable. When should
>> you use & and when &&? Judging by how @ has gone, I think the answer
>> will be simple: "Always use &, unless the docs for some third-party
>> library say to use &&", in which case I think it should be okay.
>>
>> ChrisA
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list