Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Almost as good as Microsoft Office's tristate enum with 5 states (three of them not supported), where 0 is False and -1 is True:

http://msdn.microsoft.com/en-us/library/aa432714(office.12)....



Obviously tri-state refers to False, True and Not Supported. :)


Some idiot is probably using booleans in some magic "arithmetic". A collegue once told me returning 1 for truth was handy because he could sum the results after a map, and compare the sum to the count of input elements to see if all succeeded. This only slightly more "handy" than returning TRUE and ANDing the result because you can say "X/N succeeded" (leaving the user to wonder which N-X failed is fine, I guess.)


Sir, you owe me a new keyboard.


This is how Visual Basic 6 and below worked; True was -1 and False was 0, so that bitwise and logical operators could be unified.


Presumably this is because -1 is all bits on in two's complement (http://en.wikipedia.org/wiki/Twos_complement).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: