"goto fail" is a well-known error handling mechanism in open source
software, widely reputed for its robusteness:
http://opensource.apple.com/source/Security/Security-55471/libsecurity_ssl/lib/sslKeyExchange.c
https://www.gitorious.org/gnutls/gnutls/source/6aa26f78150ccbdf0aec1878a41c17c41d358a3b:lib/x509/verify.c
I believe Python needs to add support for this superior paradigm.
It would involve a new keyword "fail" and some means of goto'ing to it.
I suggest "raise to fail":
if (some_error):
raise to fail
fail:
Unless there are many objections, this fantastic idea might be submitted
in a (short) PEP somewhere around the beginning of next month.
There is some obvious overlap with the rejected "goto PEP" (PEP 3163)
and the Python 2.3 goto module. However, the superiority of goto fail as
error generation and error handling paradigm has since then been
thoroughly proven.
https://mail.python.org/pipermail/python-ideas/2014-March/02...Please reconsider the Boolean evaluation of midnight
11–20 of 218 posts
Re: Please reconsider the Boolean evaluation of midnight
#12While I agree this is surprising behavior and I wouldn't design an API this way, it is documented behavior. From the docs: "in Boolean contexts, a time object is considered to be true if and only if, after converting it to minutes and subtracting utcoffset() (or 0 if that’s None), the result is non-zero" Changing at this point would possibly break code that relied on documented library behavior. That's not a responsi…
Simple is better than complex.
Re: Please reconsider the Boolean evaluation of midnight
#13That philosophy, taken to its logical conclusion, results in everything being broken forever.
Re: Please reconsider the Boolean evaluation of midnight
#14While I agree this is surprising behavior and I wouldn't design an API this way, it is documented behavior. From the docs: "in Boolean contexts, a time object is considered to be true if and only if, after converting it to minutes and subtracting utcoffset() (or 0 if that’s None), the result is non-zero" Changing at this point would possibly break code that relied on documented library behavior. That's not a responsi…
Re: Please reconsider the Boolean evaluation of midnight
#15Lots of Python objects are falsey: empty lists, empty strings, etc. So it's never a good idea to write "if " when you mean "if is not None". This is pretty well-known, I thought.
if datetime.time(0, 0, 0):
print "foo"
else:
print "bar"
to print "bar"Re: Please reconsider the Boolean evaluation of midnight
#16Whilst reading that thread, I stumbled accross: "goto fail" is a well-known error handling mechanism in open source software, widely reputed for its robusteness: http://opensource.apple.com/source/Security/Security-55471/libsecurity_ssl/lib/sslKeyExchange.c https://www.gitorious.org/gnutls/gnutls/source/6aa26f78150ccbdf0aec1878a41c17c41d358a3b:lib/x509/verify.c I believe Python needs to add support for this superior…
Re: Please reconsider the Boolean evaluation of midnight
#17(And 0 == False, "" != False, but both 0 and "" are considered false? C'mon Python, that's borderline JavaScript territory.)
Re: Please reconsider the Boolean evaluation of midnight
#18While I agree this is surprising behavior and I wouldn't design an API this way, it is documented behavior. From the docs: "in Boolean contexts, a time object is considered to be true if and only if, after converting it to minutes and subtracting utcoffset() (or 0 if that’s None), the result is non-zero" Changing at this point would possibly break code that relied on documented library behavior. That's not a responsi…
Explicit is better than implicit. Simple is better than complex.
BTW, do you know the original author of the Zen of Python has posted to this very dicussion (while also being the orginal author of said module):
https://mail.python.org/pipermail/python-ideas/2014-March/02... https://mail.python.org/pipermail/python-ideas/2014-March/02...
Re: Please reconsider the Boolean evaluation of midnight
#19I've never seen a good argument for anything beside "false" to be considered false. Likewise for "true". Keystrokes are not a commodity for most coders, and compilers are not dumb; just be explicit and write "!= 0" or whatever. (And 0 == False, "" != False, but both 0 and "" are considered false? C'mon Python, that's borderline JavaScript territory.)
Re: Please reconsider the Boolean evaluation of midnight
#20Lots of Python objects are falsey: empty lists, empty strings, etc. So it's never a good idea to write "if " when you mean "if is not None". This is pretty well-known, I thought.
There's nothing about midnight that makes sense for it to behave as Falase.