Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'case.': 0.05; 'none:': 0.05; 'exception.': 0.07; 'false,': 0.07; 'null,': 0.07; 'undefined': 0.07; '"if': 0.09; 'subject:while': 0.09; 'language': 0.14; 'value.': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance,': 0.17; 'appropriate': 0.20; 'not,': 0.21; 'received:209.85.214.174': 0.21; "i'd": 0.22; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'leave': 0.26; '(see': 0.27; 'am,': 0.27; 'andrew': 0.27; 'message-id:@mail.gmail.com': 0.27; 'went': 0.28; 'objects': 0.29; 'maybe': 0.29; 'problem.': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'agree': 0.34; 'received:google.com': 0.34; "won't": 0.35; 'received:209.85': 0.35; 'but': 0.36; 'be.': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'most': 0.61; 'necessarily': 0.63; 'gone': 0.64; 'jul': 0.65; 'obvious': 0.71; 'truth': 0.75; 'around,': 0.84; 'easy!': 0.84; 'obvious.': 0.84; 'do:': 0.91; 'rick': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=jOn9Mip+LzA5mo10xVC6rsM1d6jloJTwhvGasyuKaX8=; b=g8HiOVxdkyIJgWK6SNuMjTqsjhwue8GcZyFvcylxRCktI9i98cnvfj+JES4IpauC+j Gtm7kx9pNm/4JDFHX8D9PwnHFv3D8eGYmN1WtL5zQOirNmVC09QpA/dSGHhu6ggSElan xAMyC8RzvQDAylsv3EqSHbhf6zKpf6rd8ElCHl1SA6ZpnLseHZkCmqF97HII2C96oFsr uw+Aft4CRpOoxn1Mds3/rJXHW2RTz5wH915PQ+jgGZylvwNnxsodcvEA5qjUB7UQsOq8 lc+HGe8VnHTDEcRrancHNG4Kitw7+DB8m3TvwlziZoac0aAM2o29r75M1LNbJMMLn79M r1ow== MIME-Version: 1.0 In-Reply-To: <5004C697.8020809@gmail.com> References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <50037eab$0$29995$c3e8da3$5496439d@news.astraweb.com> <50047A84.6020208@gmail.com> <5004b543$0$29978$c3e8da3$5496439d@news.astraweb.com> <5004C697.8020809@gmail.com> Date: Tue, 17 Jul 2012 12:13:48 +1000 Subject: Re: Implicit conversion to boolean in if and while statements From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342491231 news.xs4all.nl 6961 [2001:888:2000:d::a6]:44420 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25452 On Tue, Jul 17, 2012 at 11:57 AM, Andrew Berg wrote: > I could do: > > if has_message: > send('{command} {args} :{message}') > else: > send('{command} {args}') > > but then I'd have to make sure has_message stays accurate since message > won't necessarily be. Or maybe I could leave message undefined and catch > the appropriate exception. However, using None is the cleanest and most > obvious. > > I know Rick likes to troll, but I do agree with him that "if something:" > for arbitrary objects can be ambiguous or confusing. I don't think > if/while must have True or False, but not every object has an obvious > truth value. Using None when '' is a valid token is the right thing to do (see also, for instance, SQL's NULL, which is often used the same way). And then you have gone away from the language's idea of whether a string is truthy or not, so you get explicit: if message is not None: send('{command} {args} :{message}') Easy! Or if the language went the other way ("all strings are true"), it would be the other way around, you'd use "if message!=''" for the other case. It's not a difficult problem. Carry on bikeshedding. :) ChrisA