|From:||Paul Moore <p.f.moore-Re5JQEeQqe8AvxtiuMwx3w-AT-public.gmane.org>|
|Subject:||Re: Please reconsider the Boolean evaluation of midnight|
|Date:||Wed, 5 Mar 2014 10:44:07 +0000|
On 5 March 2014 10:31, Masklinn <masklinn-wgwPHP1t4nvk1uMJSBkQmQ@public.gmane.org> wrote: > Side-effect of e.g. an object with an optional (nullable) time field, > the developer didn't realise a time could be false-ish (because > seriously?) and then it turns out code along the lines of > > if event.start_time: > # stuff > > unexpectedly fails if start_time is midnight. Yeah, I was classing that as "application bug" and it's easy to fix with an "is not None". Agreed that the odd behaviour of time in a boolean context is why this whole class of bugs exists, but it's only a subclass if the wider problem that people shouldn't truth-test values without thinking - an explicit test is always better (explicit is better than implicit and all that). I actually find the idea of truth-testing a value that's expected to have a type that is always true *more* unintuitive than an explicit "is not None", so I'd fix the above code regardless of what the truth value of midnight is. Paul _______________________________________________ Python-ideas mailing list Python-ideas-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Copyright © 2014, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds