main() returns 0 for success, but I expect that is owed more to Unix.
A lot of (e.g. Linux) system calls return 0 for success and an error value on error, but again that's more down to Unix than C.
"0" is not a "truthy" exit code for a system call, it rather denotes the absence of an error.
In my view, a value X being "truthy" means that `bool(X)` evaluates to TRUE, or `if(X)` gets executed.
what is a reasonable alternative?
(this isnt the same as 0 false and 1 true)
success vs. fail
is different than: true vs. false
They're both binary, but only one is boolean.In Hoon/Nock, `if(0)` literally gets interpreted as True. That's insane.
lambda x. lambda y. x
and lambda x. lambda y. y
so that "if b then x else y" is represented by "b x y".
When identifying booleans with bits, it seems natural to write this as "bit x_0 x_1" rather than "bit x_1 x_0" where the arguments seem to be in the wrong order.This is one possible justification for identifying true with 0 and false with 1.
a = ENV['A']&.to_i || 1
and then run the program with A=0 to set a to 0.(Any string starting with 0 that doesn't evaluate to a different number also works - but "0 but true" is specifically exempt from causing warnings).
DBI uses "0E0" instead, which I guess more reliably evaluates to 0 outside Perl, and still doesn't cause warnings.
it's unconventional, but no more insane than 0 = false, which, again, _is_ insane, but conventional.
i'm not bothered either way
(or, if instead of mod 2, you use min(1,a + b) to keep things in the set, then + becomes or )
To use 0 as true and 1 as false, you don't get nice things like this. It's not nice.
Well.. I guess * becomes or. But, + (mod 2) becomes, uh, xnor , and (min(1,a+b)) becomes, and...
ok well I guess that's not as bad as I thought.
Still a bad decision imo though.