Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'exception.': 0.09; 'function:': 0.09; 'lst': 0.09; 'pointless': 0.09; 'subject: [': 0.09; 'cc:addr:python-list': 0.11; 'bool': 0.16; 'boolean': 0.16; 'cc:name:python list': 0.16; 'finds': 0.16; 'readable': 0.16; 'subject:"]': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'coding': 0.22; 'cc:addr:python.org': 0.22; 'subject:problem': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'first,': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'testing': 0.29; 'am,': 0.29; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'implicit': 0.31; 'time:': 0.31; 'subject:with': 0.35; 'convert': 0.35; 'editor': 0.35; 'johnson': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'skip:& 10': 0.38; 'rather': 0.38; 'tell': 0.60; 'conversion': 0.61; 'firm': 0.61; 'save': 0.62; 'myself': 0.63; 'subject:The': 0.64; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'truth': 0.81; '"hey,': 0.84; '11:44': 0.84; 'belief': 0.84; 'rick': 0.93; '2013': 0.98 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 :cc:content-type; bh=BXaUlF4FSsFr/WXx+bTGrHNzTsiD9h2gbRUI+wkT7Nw=; b=gzG9tY3FD+TWkhqXgfGW1s8/cPn5dFNMqVmlRJH61XJJ3FVMG9wFHnVGbzR6voOSRe dBJZtNxev8PiPldjO93HRiOYP4LLNEsBskYqzim69a4WESv6efUcXZizOglUEJ7X5OgA VmcPlWVWJ1J2u2/Ow/7AyjOTl29J0LdasXij833KVaoWfgL+v6QVCU3wpT85ir5VGMFy guVNICi/rlcFtj2N3a85hnFIQMYMdaQY14xID2Q95xXZWSSbWk30cASLR9RdzYJghDB5 gZyY3cZmVjWmIStaneEUXVszdLdxMLl3B1zndFP2N54rkF3BdDPNiTc4C3vqUwpmCJIt D3nA== MIME-Version: 1.0 X-Received: by 10.42.250.202 with SMTP id mp10mr13416985icb.21.1370367143976; Tue, 04 Jun 2013 10:32:23 -0700 (PDT) In-Reply-To: References: <687dea63-84da-4c45-9366-cb5a10665d1f@googlegroups.com> <51ab95d5$0$29966$c3e8da3$5496439d@news.astraweb.com> <51ad7daf$0$11118$c3e8da3@news.astraweb.com> Date: Tue, 4 Jun 2013 13:32:23 -0400 Subject: Re: Bools and explicitness [was Re: PyWart: The problem with "print"] From: Jason Swails To: Rick Johnson Content-Type: multipart/alternative; boundary=20cf3010e6c9d42adf04de57768d Cc: python list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 122 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370367147 news.xs4all.nl 15947 [2001:888:2000:d::a6]:54030 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46946 --20cf3010e6c9d42adf04de57768d Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jun 4, 2013 at 11:44 AM, Rick Johnson wrote: > > This implicit conversion seems like a good idea at first, > and i was caught up in the hype myself for some time: "Hey, > i can save a few keystrokes, AWESOME!". However, i can tell > you with certainty that this implicit conversion is folly. > It is my firm belief that truth testing a value that is not > a Boolean should raise an exception. If you want to convert > a type to Boolean then pass it to the bool function: > > lst = [1,2,3] > if bool(lst): > do_something > > This would be "explicit enough" i f lst: do_something is equivalent to if bool(lst): do_something why not just have your editor autobool so you can spend more time coding and less time stamping around? That way the person that finds booled code more readable can have what he wants and the people that find it less readable can have what they want. Win-win BTW, you should do pointless comparisons like if condition is True: do_something rather than if condition == True do_something --20cf3010e6c9d42adf04de57768d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

<= /div>


On Tue, = Jun 4, 2013 at 11:44 AM, Rick Johnson <rantingrickjohnson@gmail= .com> wrote:

This implicit conversion seems like a good idea at first,
and i was caught up in the hype myself for some time: "Hey,
i can save a few keystrokes, AWESOME!". However, i can tell
you with certainty that this implicit conversion is folly.
It is my firm belief that truth testing a value that is not
a Boolean should raise an exception. If you want to convert
a type to Boolean then pass it to the bool function:

=A0 =A0 lst =3D [1,2,3]
=A0 =A0 if bool(lst):
=A0 =A0 =A0 =A0 do_something

This would be "explicit enough"

i
f lst:
=A0 =A0 do_something

is equivalent to

if bool(lst):
<= /div>
=A0 =A0do_something

why not just have your editor autobool so you can spend more time coding an= d less time stamping around? =A0That way the person that finds booled code = more readable can have what he wants and the people that find it less reada= ble can have what they want.

Win-win

<= div>
BTW, you should do pointless comparisons like

if condition is True:
=A0 =A0 do= _something

rather than

if condition =3D=3D True
=A0 =A0 do_something
--20cf3010e6c9d42adf04de57768d--