Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail 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; 'syntax': 0.03; 'attribute': 0.05; 'guido': 0.05; 'none,': 0.05; 'function,': 0.07; 'means,': 0.07; '"if': 0.09; 'semantics': 0.09; 'subject:while': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; '"if"': 0.16; '*must*': 0.16; '*never*': 0.16; 'hell.': 0.16; 'none"': 0.16; 'record,': 0.16; 'syntax,': 0.16; 'syntax.': 0.16; 'trap': 0.16; 'workings': 0.16; 'wrote:': 0.17; 'issue.': 0.20; 'interpret': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'example': 0.23; '15,': 0.23; 'statement': 0.23; 'this:': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'accomplished': 0.29; "d'aprano": 0.29; 'implies': 0.29; 'lies': 0.29; 'steven': 0.29; 'objects': 0.29; 'point': 0.31; 'problem': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'false': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'test': 0.36; 'should': 0.36; 'too': 0.36; '(for': 0.37; 'rather': 0.37; 'received:209': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:209.85.214': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'think': 0.40; 'july': 0.60; 'save': 0.61; 'first': 0.61; 'road': 0.63; 'ever': 0.63; 'more': 0.63; 'jul': 0.65; 'believe': 0.69; 'manner': 0.74; 'money': 0.74; '(is': 0.84; 'confusing': 0.84; 'grave': 0.84; 'intentions': 0.84; 'received:209.85.214.184': 0.84; 'received:mail-ob0-f184.google.com': 0.84; 'mistake': 0.91 Newsgroups: comp.lang.python Date: Sun, 15 Jul 2012 09:50:05 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=166.249.198.115; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 166.249.198.115 MIME-Version: 1.0 Subject: Re: Implicit conversion to boolean in if and while statements From: Rick Johnson To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342371756 news.xs4all.nl 6853 [2001:888:2000:d::a6]:57634 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25358 On Sunday, July 15, 2012 11:19:16 AM UTC-5, Ian wrote: > On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano > wrote: > > (For the record, I can only think of one trap for the unwary: time > > objects are false at *exactly* midnight.) >=20 > Ugh, that's irritating. I can't think of any scenario where I would > ever want the semantics "if timeval (is not midnight):". This > reinforces the point that if you only want to test whether you have > None, you should use "is not None" rather than relying on __bool__. I think this issue is not so much a "bool test" vs "type test", but more an= ambiguous syntax issue. Consider this: ## EXAMPLE A ## py> if money: ... do_something() The syntax "if money" implies we are testing/measuring some attribute of "m= oney", but what exactly about money are we testing/measuring? The problem l= ies in the syntax. To understand this syntax, we must first interpret what = *IF* means, and we should *NEVER* need to interpret such a well defined wor= d as *IF*! This syntax is far too opaque. Consider the alternative: ## EXAMPLE B ## py> if bool(money): ... do_something() Now we have a hint. Even if we don't understand the inner workings of the "= bool" function, we *do* understand that the statement "bool(money)" *must* = return True or the block *will not* execute.=20 We must NEVER present "if" in such confusing manner as ExampleA. I believe = Guido made a grave mistake allowing this syntax to flourish. His intentions= where noble, to save people a few keystrokes, but all he accomplished was = to pave a road directly into hell.=20 "Explict is better than Implict"