Bools and explicitness [was Re: PyWart: The problem with "print"]

Jason Swails jason.swails at gmail.com
Tue Jun 4 13:32:23 EDT 2013


On Tue, Jun 4, 2013 at 11:44 AM, Rick Johnson
<rantingrickjohnson at 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:
>
>     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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130604/897485b3/attachment.html>


More information about the Python-list mailing list