Earlier quoted context omitted.
My understanding is that the responder is saying that "That test does not mean what you are intending it to mean, it means something else that we've documented. We won't make it mean what you would like it to take make your incorrect code work, at the expense of breaking code that is using it in the documented way". I started on the side of the original person but was persuaded round by the responder. "if x:" means s…
You can't document your way out of a usability problem.
Please reconsider the Boolean evaluation of midnight
121–130 of 218 posts
Re: Please reconsider the Boolean evaluation of midnight
#122Earlier quoted context omitted.
This is what is plaguing the ocaml compiler and standard library. Overconservatism with respect to obscure features. For example, a patch was written to speed up hashtables (IIRC), and was rejected because it would change the result of hashing format strings (type-safe format strings have a different type from plain strings). I can't imagine a single application where you would need to preserve the value of hashed fo…
Type-safe format strings should never be mixed with plain strings, constant strings, byte strings, unicode strings, batteries strings, byte array strings, char array strings, string buffers or any other type of string supported by ocaml. Keep your types pure and never mix them with any other types. Never . And you will never have any problem. And these python developers are lunatics. It is preposterous to use 'if' co…
Re: Please reconsider the Boolean evaluation of midnight
#123Lots 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.
A big part of it is about user expectations. I would be shocked if any experienced Python programmer who wasn't familiar with this exact implementation detail expected the following: if datetime.time(0, 0, 0): print "foo" else: print "bar" to print "bar"
Re: Please reconsider the Boolean evaluation of midnight
#124Python has weird ideas about comparisons, I'm pretty sure it's the only language where this is possible: https://eval.in/113749
Re: Please reconsider the Boolean evaluation of midnight
#125Python has weird ideas about comparisons, I'm pretty sure it's the only language where this is possible: https://eval.in/113749
Re: Please reconsider the Boolean evaluation of midnight
#126Earlier quoted context omitted.
Equivalently, taken to its logical conclusion, it results in more people writing better code.
if var: ... is better code (for my value of better, which is subjective) than: if var is not None: ...
From PEP-8: http://legacy.python.org/dev/peps/pep-0008/
Re: Please reconsider the Boolean evaluation of midnight
#127Earlier quoted context omitted.
Equivalently, taken to its logical conclusion, it results in more people writing better code.
Would you intentionally introduce language features that break functionality for people who don't follow style guidelines? I certainly hope not. The real problem with your argument is that the poorly-styled code of people who haven't learned better yet is in production . This isn't a theoretical exercise. This is a tool used in industry, and "teaching people to style their code better" is not a valid excuse for costi…
Industry must bend before truth, not bend truth over itself...
Re: Please reconsider the Boolean evaluation of midnight
#128Re: Please reconsider the Boolean evaluation of midnight
#129Earlier quoted context omitted.
This is what is plaguing the ocaml compiler and standard library. Overconservatism with respect to obscure features. For example, a patch was written to speed up hashtables (IIRC), and was rejected because it would change the result of hashing format strings (type-safe format strings have a different type from plain strings). I can't imagine a single application where you would need to preserve the value of hashed fo…
Type-safe format strings should never be mixed with plain strings, constant strings, byte strings, unicode strings, batteries strings, byte array strings, char array strings, string buffers or any other type of string supported by ocaml. Keep your types pure and never mix them with any other types. Never . And you will never have any problem. And these python developers are lunatics. It is preposterous to use 'if' co…
Re: Please reconsider the Boolean evaluation of midnight
#130I'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.)
I think the history of Lisp is instructive. In traditional Lisp all the way through Common Lisp, the empty list, also known as NIL, is false, and everything else is true. This is a relatively benign form of truthiness, but even so, the type-punning it invites tends to make programs less clear (even though they're a little shorter).
Since Scheme was a clean sheet design, Steele and Sussman had the opportunity to change this, and they did: Scheme has explicit '#t' and '#f' literals, and no implicit conversions from other types to boolean. I think their reasoning was sound.