3 ms·
By way of contrast: a friend of mine was once working on a contract job in Visual Basic. One day he edited an "if" statement which basically said (I don't know
by ScottBurson 16y ago
By way of contrast: a friend of mine was once working on a contract job in Visual Basic. One day he edited an "if" statement which basically said (I don't know VB syntax, but this will give you the idea):
(0) if foo() then do_something() else do_something_else()
It turned out that it was unnecessary to do anything in the "then" branch:
(1) if foo() then no_op else do_something_else()
My friend, quite naturally, changed that to this:
(2) if not foo() then do_something_else()
After several hours of frustration, my friend finally realized that the transformation from (1) to (2) is not valid in Visual Basic. How can this be? As I recall, there is some false value in VB such that its negation is also false.
This is the kind of hell languages create when they try to be helpful by having lots of different false values (0, the empty string, the empty list, and of course "false") and at the same time have lots of implicit conversions.
So, be glad that Clojure has only two "falsey" values.
- snprbob86 16y agoI'm not sure what particular issue your friend ran into, but here's one strange fact about booleans in pre-.net versions of Visual Basic: True is defined as -1. This allowed there to be a single, type-agnostic "not" operator. There was no distinction between binary and logical negation. C, of course, has ~ and ! operators and uses 0 and non-zero for truthiness. When calling into non VB "Classic" modules, the mapping of boolean values can be unnecessarily confusing.