- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
new Array(
true,
false,
OR_ELSE
);
Admin
You beat me to it.
Absolutely - there is nothing wrong with tertiary logic: true, false and unknown. A few moments thought for the C programmers out there should enable you to work out the logical and pattern in tertiary logic. Here's the logical or for example:
V| T F ?
--------
T| T T T
F| T F ?
?| T ? ?
Cheers,
Justin.
Admin
We have a phrase for this: "clearly not a logician". I suppose you don't believe that the empty set exists, either?
Admin
That would be because return status of 0 is success... And return status' have more than 2 possibilities.
Admin
This took me a few moments to put together. It makes sense inside a command shell.
Admin
@Eric: I see what you mean. I can't think of a better name for that either - maybe EditableState or something, but I don't think that's better. It's a minor WTF, since it's pretty obvious what's going on.
OTOH, the OP was a real WTF, since he was calling it "Bool", which may or may not have anything to do with files.
Now, someone said that it may be on Unix where most things are represented by files, but I'm not sure if, say, a checkbox is represented by a file or not. It would seem incredibly strange to have something like
checkbox1.Checked = Bool.FileNotFound;
A boolean value, by definition, can only ever be true or false. Now, before anyone shouts about nulls, they are used when there is NO value at all. A boolean shows whether something is true or false, and you'd use null instead to show that there is no data either way, or maybe that the question doesn't apply in that situation. By the same token, a null int isn't actually a number - it's an indication that there is no numbber to use in that situation.
Admin
Remember that most of us are doing programming, not mathematical research. Our programs generally model something. The fact that the mathematical concept of Boolean does not include a third Unknown/NA state does not make that construct any less valid within our programs. If you need to be rigorous, just model your pragmatic booleans as two boolean attributes: the boolean value and a null/not null indicator value. In fact, this is precisely the technique that SQL<->procedural language bridges like Pro*C use to indicate a null value in a host language primitive type.
Admin
I think it makes a lot more sense this way:
W| T F ?
--------
T| T T T
F| T F ?
?| T ? ?
Admin
I was trying to point out that a third option in the form of NULL is useful, though I'd rather simply have true or false, then set it to null if needed:
bool fileOpen; //can only be true or false
if(!FileExists('something.txt')) { fileOpen = null; //not storing a value }
It's a personal preference. It would be acceptable for bool to allow a third option explicitly, rather than using the built-in null value like (that's available for all/most datatypes) I have used here. However, for other things, such as shown in the OP, calling it BOOL is confusing because people will try to use it in situations where the third option simply doesn't make any sense. In that situation, you really do need to call it something else.
Admin
Do a quick search on "ternary" or "trinary" and wake up to the way the world will go one fine day! and There is trinary logic and it kinda works in java already as you can have true, false and un-initalised!
Admin
Once more for the hard of reading:
For other things, such as shown in the OP, calling it BOOL is confusing because people will try to use it in situations where the third option simply doesn't make any sense. In that situation, you really do need to call it something else.
"uninitialised" is really analagous to "null" - the value can either be true or false but you haven't set it yet, so it's neither. Perhaps a little more specific, but certainly not on the same lines as FileNotFound.
Besides, the only thing I can find on "ternary" in Java is the ternary operator that you get in C++ (test ? true : false), which is actually still binary logic - the "ternary" part of the name refers to thefact that it takes 3 operands.
Some people have written Ternary classes (such as http://www.cs.princeton.edu/introcs/60circuits/Ternary.java.html), though these aren't standard AFAIK. And the people who have done that haven't been stupid enough to call their work "boolean" have they?
Admin
Digital Electronics guru's know that there is, of course: true (1), false (0) and don't care (X).
Admin
Yes, your way makes quite a difference.
ok
dpm
Admin
No - you have missed the point here. Remember the Y2K bug - no one thought that their software would last until the year 2000?
He is merely catering for the advent of the tri-state bit in the quantum computer.
It can be true, false or in an indeterminate state. In this case, FileNotFound is the indeterminate state.
It can also be expressed thus:
public enum cat
{
alive;
dead;
noIdea;
}
Of course, once you know the result, then it's determinate. So it can never be noIdea. You with me?
Smudge
PS. Do you think that sometimes Schrodinger opened his lunch box and his sandwiches were there, and sometimes, they weren't?
Admin
Not sure if you were responding to me. Either way I couldn't work out everything you were saying - what exactly does the Y2K bug have to do with it?
"Of course, once you know the result, then it's determinate. So it can never be noIdea. You with me?"
So if I understand correctly, this is exactly what I was saying. In your example, there's no issue beause you've not used the word bool.
The problem isn't that he had a third state (though there's a perfectly valid case that this should be achieved by other means), but that he had a third state called FileNotFound. Now, that's fine if you're dealing specifically with files, but in this case we're not, we're dealing with redefining a widely-used datatype. That's fine too, as long as you cater for the fact that it will be used in lots of situations.
The problem is that elsewhere in the program we might re-use this enum in a context where FileNotFound is a nonsensical value. That's an easy mistake to make because there's nothing about this enum to suggest it's specific to files. If there was, it would be a strange coding practice, rather than a serious WTF.
I'm personally of the opinion that bools should still only have two states, and the bool itself should be null when there's no data. If that's not possible, then don't call it a bool. Would you do something like this:
string databaseConnectionString = "I like monkeys";
Admin
The mathematical concept of Boolean algebras does NOT limit the number of elements.
Admin
I'd really like to know how you figured out my company's connection string. PM me if necessary.
Admin
johnl - that was a bit of a tongue in cheek reply on my part. I agree with you though.
In any case, defining something with the same name as a primitive is a bad idea. If it needs redefining, it needs a new name.
This is just wrong - we all know that because we can code (albeit in my case, badly...) ;-)
Admin
Ah, right. I wasn't sure.
"In any case, defining something with the same name as a primitive is a bad idea. If it needs redefining, it needs a new name."
Yeah, you're probably right.
YTram, I can't just give away all my l337 h4xx0r trade secrets, now can I? ;)
Admin
You sorta already have a "datatype" you could use for this... RGB 00-FF:00-FF;00-FF.
So, what does a dark mauve mean to you?
Admin
I also prefer my Pool to not have P in it. That would be... unsanitary.
Admin
Not in Java. There is a compiler warning you can get when using an possibly uninitialized local variable, but there is no such thing as an uninitialized variable at runtime - the compiler forces you to initialize local variables, and member variables are automatically initialized to null, 0 or false.
Admin
Bits good, tits better? And how would the relation of bytes and nibbles to tits be?
<ponders>
Admin
Nope. It's called a vacous truth.
http://en.wikipedia.org/wiki/Vacuous_truth
Admin
And a Boolean object can't be inicializated as undefined. Either it holds true or it holds false. If it is null then there is no Boolean object at all.
You can of course overload the meaning of not having a Boolean object as not being sure of the condition it represents:
Admin
"Bits good, tits better? And how would the relation of bytes and nibbles to tits be?"
Like tits, but bigger? I think we should let this line of conversation stop there...
Admin
What's with you people and your damn elephants?
From wikipedia:
Admin
This works in C#.
Admin
Truth is beauty [H]
Admin
Incorrect. This corresponds to the predicate logic formula "ForAll(x): (IsElephant(x) and IsDeepSeaDwelling(x)) implies CanFly(x)". In the model of the real world, "IsElephant(x) and IsDeepSeaDwelling(x)" is false for all x, thus the implication is always true. q.e.d.
Admin
Making implications evaluate to false if the prerequisite is not met would be a seriously nonsensical thing to do.
The formula you've given ("All deep-sea dwelling elephants can fly, and there exists at least one deep-sea dwelling elephant") is not equivalent to dubwai's example.
Admin
Shouldn't the equivalent of a nibble be a nipple?
Admin
S = { True, False, FindBetterAxioms }
Admin
How Hobbesian
Admin
If half a Byte is a nibble, would half a tit be a nipple?
Admin
And it would operate under Boleyn logic...
Admin
Not to be completely pedantic but....
enum Bool
{
True,
False,
NULL,
Nothing
};
Admin
Truth is Beauty; Beauty Truth. But if I get out of this one alive, I'll never eat meat again.
(Nick Danger - Third Eye)
Admin
Let S = {All sets s such that s is not an element of s}
If S is an element of S ==> S is not an element of S
If S is not an element of S ==> S is not an element of S
(Bertrand Russell Paradox)
Admin
public bool? foo;
foo = false;
foo = true;
foo = null;
C# 2.0 ;)
Admin
You must be kidding - that works in C#? Are they using objects behind the scenes for their bool primatives? What is the memory footprint of a boolean primative in C# then, or does it cast null to false as it is assigned to an actual primate bool? Is (false == null) true?
As far as people mentioning that if that was an unfortunate name for the enum - would anyone really turn a bool response into an enumeration with secondary error flags?
Personally, I think that is where you would want to use a FileNotFound exception, and be smart enough to check for the file before the function call to get the true/false response.
IMHO If you return a value that is 'true' and another that is 'false' no matter how you cut it, !false should always be true and !true should always be false, otherwise you need "if (response != true && response != false) getMysteryPrize(); " since some guy could have added to the returned enum without you knowing, and "(!true && !false) == true" should always be a WTF.
About the flying sea elephants:
I think what is said, is if "all the elephants under the sea can fly" and you ask "are there any elephants under the sea that can't fly?" you have to respond "there are no elephants that can't fly under the sea." If there are no elephants under the sea that can't fly, then can't they all fly down there? They all can pass the test, all zero of them. Of course "all the elephants under the sea can't fly" is also true, so it is not a statement of actual boolean logic (any more than filenotfound)
Its more a demonstration how truth/false tests are limited and can't answer all questions in a useful way, only some. Take "True of false: You enjoyed stealing the money." as an example: Yes or No only make any sense if you did steal the money.
Just like "bool doesTheFileHaveNeatStuffInIt(File f)" only makes sense if there is a file to check. The answer isn't to provide more response options in addition to true/false, but not to ask for a single true/false response when the condition's result relies on another condition being true that hasn't been tested.
I can't wait to see this one though for a get milisec function:
Admin
meant that to say
...but I used gt/lt chars and they didn't show
Admin
You just fell for a troll because bool? is C# compiler sugar for declaring a Nullable<bool>, which is a struct, and is not the primitive type bool (no question mark).
Admin
It doesn't matter what True and False are in terms of bit values as long as they're used consistently throughout the code. Don't think that True "should be" 1 and False "should be" 0; True could be 3921 and False could be 2005. It really doesn't matter.
As for the "FileNotFound"... I think the programmer is actually quite clever to come up with such a construct. The practicality of this is not evident at first - but if you think about it, it's a good way to propagate the condition across the entire program via returning it through various functions. However he could've cleaned it up a little by eliminating False and renaming True to Success. Then it is easy to see that one can incorporate various other error conditions in there too -
AccessDenied
FileInUse
PathNotFound
ReadError
WriteError
...
Admin
<FONT face="Courier New" size=2>i post, therefore i am.</FONT>
Admin
<FONT face="Courier New" size=2>you said it, mon.</FONT>
Admin
<FONT face="Courier New" size=2>in my country, elephant burgers are amazing delicacies.</FONT>
Admin
Troll?
Its bloody tasty sugar, makes dealing with databases that little bit easier.
Admin
Yes, sure, I think he has his own enum of Ints :)
Admin
if (true)
{
return 1;
} elseif (false) {
return 0;
} else {
return 0.5;
}