Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: Operator Precedence/Boolean Logic Date: Thu, 23 Jun 2016 09:58:56 +0200 Lines: 37 Message-ID: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de uO7VdHy5VdOpLEwKDQzB6Axuz+cTF37tqWfToh8ZqnQQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'true,': 0.04; 'received:134': 0.05; 'attributes': 0.07; 'expressions': 0.07; 'indication': 0.09; 'thu,': 0.15; '2016': 0.16; 'boolean': 0.16; 'conditional': 0.16; 'delayed,': 0.16; 'mine.': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'rule.': 0.16; 'substitute': 0.16; 'true:': 0.16; 'wrote:': 0.16; 'typing': 0.18; '>>>': 0.20; 'lawrence': 0.22; 'simpler': 0.22; 'am,': 0.23; 'originally': 0.23; "python's": 0.23; 'header :In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'define': 0.27; 'values': 0.28; 'went': 0.28; 'larry': 0.29; 'operators': 0.29; 'other,': 0.29; 'types.': 0.29; 'subject:/': 0.30; 'anywhere': 0.30; 'class.': 0.30; 'received:be': 0.30; 'everyone': 0.31; 'point': 0.33; 'class': 0.33; 'steven': 0.33; 'could': 0.35; 'instance': 0.35; 'something': 0.35; 'expected': 0.35; 'but': 0.36; 'needed': 0.36; '(and': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'wrong': 0.38; 'why': 0.39; 'whatever': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'real': 0.62; 'more': 0.63; 'act': 0.67; 'applying': 0.70; 'entitled': 0.70; 'truth': 0.79; "d'aprano:": 0.84; 'enhances': 0.84; 'pardon': 0.84; 'schreef': 0.84; 'strengths': 0.84; 'write:': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArIIAHYeUleGuA9G/2dsb2JhbABehFsBvRCGEgKCAAEBAQEBAWaEbQEBBCMPAUURCxgCAgUWCwICCQMCAQIBRRMIAogrsU2NPoNbAQslgQGFJoRNhQyCNYJZBZhFgVeMTYkzhWmPUlSDcIp+AQEB User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0 In-Reply-To: <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <576B96C0.2040106@rece.vub.ac.be> X-Mailman-Original-References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:110378 Op 23-06-16 om 05:59 schreef Steven D'Aprano: > On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > >> On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: >> [snip] >>> I feel that’s a needlessly complicated rule. It would have been simpler >>> if boolean operators (and conditional expressions like in if-statements >>> and while-statements) only allowed values of boolean types. But that’s >>> one of the few warts in the design of Python... >>> >> Wart?? I *strongly* disagree. I find it one of the strengths of Python, >> it enhances Python's >> expressiveness. Of course, everyone is entitled to their own >> opinion...and this is mine. > Allowing any value as a truth value is just applying the principle of > duck-typing to booleans. What does that mean? As far as I understood, duck typing was that you could define any class with the same attributes and methods as an other, often a built in, at which point you could substitute instance of this new class anywhere you originally expected instance of the old class. My experience is that this doesn't work with booleans. When I need real booleans, encountering whatever else that can act like a boolean, is more often than not an indication something went wrong but the detection of it going wrong is delayed, because almost everything can act like a boolean. It is why I have sometime found the need to write: if flag is True: Because flag needed to be True, not truthy. -- Antoon Pardon