[Python-ideas] Please reconsider the Boolean evaluation of midnight

Daniel Holth dholth at gmail.com
Thu Mar 6 23:56:14 CET 2014


The obvious solution is just to fix the Python if statement to remove
implicit bool coercion. So they would all evaluate to if isinstance (x,
bool) and x. Problem solved.
On Mar 6, 2014 5:27 PM, "Ethan Furman" <ethan at stoneleaf.us> wrote:

> On 03/05/2014 07:42 AM, Paul Moore wrote:
>
>> On 5 March 2014 15:08, Yann Kaiser <kaiser.yann at gmail.com> wrote:
>>
>>>   Let me show you an actual zero:
>>>
>>>      if event.num_attendants:
>>>          prepare_cake()
>>>      else:
>>>          cancel_event()
>>>
>>> When no one is coming to your party, is is clearly a different
>>> condition than if any number of people are coming to your event.  When
>>> you read "if num_attendants", you can clearly tell this is going to do
>>> something depending on if people are coming or not.
>>>
>>
>> I'm sorry, are you really trying to say that the above code is better than
>>
>>      if event.num_attendants != 0:
>>          prepare_cake()
>>      else:
>>          cancel_event()
>>
>> ?
>>
>
> Yes.  This is Python.  blah blah blah != 0 is unnecessary boiler-plate [1].
>
> --
> ~Ethan~
>
>
> [1] In most cases.  I have used `== 0` or `!= 0` when it makes the code
> clearer, but that's pretty rare.
>
> --
> ~Ethan~
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/f135fa49/attachment-0001.html>


More information about the Python-ideas mailing list