Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107276

Re: [Python-ideas] Changing the meaning of bool.__invert__

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: [Python-ideas] Changing the meaning of bool.__invert__
Date 2016-04-18 14:41 -0600
Message-ID <mailman.156.1461012147.6324.python-list@python.org> (permalink)
References (8 earlier) <20160408014030.GL12526@ando.pearwood.info> <22279.18221.103226.654215@turnbull.sk.tsukuba.ac.jp> <20160409154305.GU12526@ando.pearwood.info> <CABDEq2mUhLMo2o=HTyxpV=pbPazakHoO-8OjFBLeKVWoZZTz4w@mail.gmail.com> <CALwzidnogG3DvUi-eybcete+Zy9KwttyOAeUCyX1nS-m4LJ2kQ@mail.gmail.com>

Show all headers | View raw


On Sun, Apr 17, 2016 at 12:24 PM, Pavol Lisy <pavol.lisy@gmail.com> wrote:
> 2016-04-09 17:43 GMT+02:00, Steven D'Aprano <steve@pearwood.info>:
>> flag ^ flag is useful since we don't have a boolean-xor operator and
>> bitwise-xor does the right thing for bools. And I suppose some people
>> might prefer & and | over boolean-and and boolean-or because they're
>> shorter and require less typing. I don't think that's a particularly
>> good reason for using them, and as you say, you do have to guard
>> against non-bools slipping, but Consenting Adults applies.
>
> They are also useful if you need to avoid short-circuit evaluation.

One can easily write functions to do that.

    def long_or(a, b):
        """Equivalent to a or b but always evaluates both expressions."""
        return a or b

long_or(a, b) may not be as pretty as a | b, but I'll argue that it's
more readable since it's up-front about its intent, whereas a | b
looks like it could just be a mistake.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Python-ideas] Changing the meaning of bool.__invert__ Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-18 14:41 -0600

csiph-web