- 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
O
It's pretty obvious you've done very little work with bitmasks. If the mask says rejected and approved, it would sure make me find out why.
Hi, Ho, Tonto, Away. . .
Admin
Ooops, kind of a reply to way back... probably didn't read far enough. Should have quoted...
Admin
The [Flags] attribute does nothing but give you a nicely formatted list of elements when you call ToString on the enum. You can still use bitFields without the flag. Try it...
Admin
.NET 1.1:
public enum BOOL
{
TRUE,
FALSE,
NOT_TRUE_OR_FALSE
}
BOOL variable = NOT_TRUE_OR_FALSE;
.NET 2.0:
bool? variable = null; // or System.Nullable<BOOL>
WTP? (what's the problem?) [:P] Oh, yes... some bad naming after all.
Admin
You forgot A_SUFFUSION_OF_YELLOW
Admin
I think it's important to distinguish between *two* things here: a boolean datatype and a boolean algebra. A boolean datatype (although possibly badly named) only has two possible values, by definition. A clearer link would have been http://mathworld.wolfram.com/BooleanAlgebra.html, IMO.
Admin
Why is that a problem? I'm sure that you wouldn't depend on TRUE being some magic value.
Admin
It's like in that movie, "White Men Can't Jump." Sometimes, Billy, when a person says TRUE, they really mean FALSE. And sometimes, when a person says FALSE, they really mean TRUE. And sometimes when a person says TRUE or FALSE, they really mean NOT_TRUE_OR_FALSE.
Admin
It's quite clear that these are intended to be used as flags. This means all these conditions are not mutually exclusive. An order may have one or more of these statuses. That's even more worrisome than having a bool that can in a state that's neither true nor false. After all, perhaps the bool is representing qubits. :-)
Admin
And Micheal Jackson.
Admin
Not really. The original was
NOT (True OR False)
Instead of
(NOT True) OR (False)
Admin
The surrealist boolean:
Admin
Actually, the Wolfram link backs up multi-valued boolean algebra, as well:
...A Boolean algebra can be formally defined as a set B of elements a, b, ... with the following properties:...
Two of the elements are called "0" and "1", but there can be many other values, as well. Of course, neither link has any concept remotely similar to the original code.
Admin
The teenager's boolean:
Admin
...A Boolean algebra can be formally defined as a set B of elements a, b, ... with the following properties:...
Two of the elements are called "0" and "1", but there can be many other values, as well. Of course, neither link has any concept remotely similar to the original code.
Admin
The adolescent-boy-at-a-drivein's boolean:
Admin
...A Boolean algebra can be formally defined as a set B of elements a, b, ... with the following properties:...
Two of the elements are called "0" and "1", but there can be many other values, as well. Of course, neither link has any concept remotely similar to the original code.
Admin
No, the bool definition is perfectly valid. Usually when you see a 3rd value, it indicates that the boolean value should not be considered.
For example, Lets say you were polling a set of objects:
obj1.Vote = true;
obj2.Vote = false;
obj3.Vote = false;
obj4.Vote = true;
obj5.Vote = false;
In this case, the majority voted false. Now consider this:
obj1.Vote = true;
obj2.Vote = NoValue;
obj3.Vote = NoValue;
obj4.Vote = true;
obj5.Vote = false;
Here, obj2 and obj3 don't have a vote. They don't care either way, so in this case their votes are not counted and the group votes true.
Admin
The WTF for me is 128 for Rejected, and 1024 for UnRejected. How is "UnRejected" different than having the bit for "Rejected" be off?
Admin
Right so that should make it easier to search for records that are both Rejected and UnRejected...
Admin
To add fuel to the fire, the opposite of true isn't false. It's not true. It's how that entire multi valuable boolean thing.
Exampes:
sad is not the opposite of happy.
short is not the opposite of tall.
wet is not the opposite of dry.
After all, we can be just fine, average height or damp. I'm making that my tagline.
Admin
what if we don't know their name is renee or chris?
Shouldn't we default all names to Pat just in case?
Admin
java.util.Boolean can be null, TRUE or FALSE.
Not so weird.
My favorite is 'unrejected.'
Admin
Hmm, tri state booleans.
I see them as more of a schrodinger's cat kind of problem. Let's say you have a web site that stores visitors in a database. This database also marks them as registered if they do so. Now you could see this registered field as a boolean, either TRUE or FALSE, they are registered or they are not, but since this is a database and you may be doing as few updates as possible, and registration was added after initial release, it allows NULL. This then becomes tri-state.
Now on to the cat. We know what TRUE and FALSE represent in the registered field, but we have a third value of NULL. As with the theoretical cat, we don't know if the visitor registered or not until we check it. Once we check we notice that it's state is not yet defined so we safely (and rightly so) assume FALSE. As schrodinger's cat suddenly dies we know that this visitor has not registered because, if he had, this value would explicitly state TRUE.
So are tri state booleans really tri state? In most cases I think not, but there could be a time when the cat is undead if you bury it in the local Pet Semetary.
Admin
That's why I said it would have been clearer to make his original point. When I went to his original link, I had to go way down the page to see what he was talking about.
Admin
Yes. http://en.wikipedia.org/wiki/Boolean_value
Admin
This is not really a huge problem, as C# requires conditionals to be boolean, therefore BOOL x; if (x) wouldn't compile. You would have to do if (x == BOOL.TRUE).
Admin
NOT_TRUE_OR_FALSE
Wouldn't the compiler just optimize this to FALSE? ;-)
(!1||0) == 0
Admin
Admin
Nobody's probably reading the third page of comments, but IMHO the true WTF is that the programmer's being inconsistent. It should have been:
Admin
In your example, I agree, there is an implied false by the null value but that is by no means the case. What if a user is asked a yes/no question, and the answer is stored on a website somewhere? TRUE means Yes, FALSE means no, and NULL means they havent answered the question yet, so it is equally likely to go either way. Sure, this doesn't meet the strict definition of "boolean" but in the real world of real problems, this is a valid consideration.
Admin
If a variable is "Boolean" it is true or false, and that's it.
If the variable can have other values, it is not "Boolean" it is a different type of logical construct.
There are plenty of logical systems that have more than true or false, THEY JUST ARE NOT "BOOLEAN".
Yeesh
Admin
With some years of business processing behind me I can assure all and sundry that the state diagram for an order can be as complex as the first enum suggests, in some companies even more so. A case can be made for the value of ALL the implied states, including unrejected, which surely is not the same as any of the others listed.
I seriously expect that these make sense as discrete states. But that's only because I am thinking about the life of an order in a complex company.
Although it is kinda hard to read, in the old days, printing a string of unspaced single characters to indicate status was commonplace, even for mutually exclusive states. Thus the use of binary values might be explained.
The disservice to us is the invitation to imagine the rest of the system. I've worked on many sound process systems that used complex state models with total validity.
I think the choice of the name BOOL is an unfortunate error of ignorance, rather than an invalid set of ennumerated values.
Is it a WTF to produce somewhat hard to understand code? I dunno - there's lots out there.
Personally, I think this is only a WTF if F = "French Kiss with no tongue (Madeline Kahn RIP)"
Admin
<FONT color=#000000>pmagill:</FONT>
Hmm, tri state booleans.
I see them as more of a schrodinger's cat kind of problem. Let's say you have a web site that stores visitors in a database. This database also marks them as registered if they do so. Now you could see this registered field as a boolean, either TRUE or FALSE, they are registered or they are not, but since this is a database and you may be doing as few updates as possible, and registration was added after initial release, it allows NULL. This then becomes tri-state.
Now on to the cat. We know what TRUE and FALSE represent in the registered field, but we have a third value of NULL. As with the theoretical cat, we don't know if the visitor registered or not until we check it. Once we check we notice that it's state is not yet defined so we safely (and rightly so) assume FALSE. As schrodinger's cat suddenly dies we know that this visitor has not registered because, if he had, this value would explicitly state TRUE.
So are tri state booleans really tri state? In most cases I think not, but there could be a time when the cat is undead if you bury it in the local Pet Semetary.
That doesn't work at all. In the schrodinger's cat problem you don't assume one or the other or neither. You assume both because you can't observe it it. So he can observe the database (with respect to the program)... s/he's just to lazy to create better checking.
meaning it exists partly as each simultaneously
Admin
Boolean does imply bivalent though, which is probably what the OP was vaguely fumbling for. If you want something that's no bivalent then you get a Heyting algebra.
Admin
Decision states. I would interpret UnRejected as someone reversing a decision to Reject This is not the same as a rejection never having occured.
Admin
Looks like the programmer is fiddling with his bits. BAD PROGRAMMER, BURN IN THE FIRES OF PURGATORY HELL!
Admin
I do like how he just makes up a boolean system with a nice rejected unrejected. It's like it can be neither, both, rejected, or unrejected. And then he tries to make up his own system of bool to match it. Wonder if he will add a third flag for user_dead or user_smacking_computer_violently when the user submits one that is unrejected followed by another that is rejected.
Admin
Well, I've managed to do that more than once. I thought it just didn't work at all. It wasn't until I tried to quote his post that I realized it wasn't an always-bug.
- - -
As far as the BOOL, I'd say that the WTF is that its third state is so poorly named. NOT_TRUE_OR_FALSE? What that that even mean?
UNKNOWN, INDETERMINATE (ala tribool), and maybe even NULL would all be acceptable. The choice of NOT_TRUE_OR_FALSE is just wierd.
Admin
This programmer is a bit outdated... the future of boolean algebra is float. 0.0 is false, 1.0 is true, and everything between 0.0 and 1.0 would be a valid boolean, but neither true nor false.
Admin
<FONT face=Arial size=2>Now there is something for 'Quote of the week, on dbdebunk.com.</FONT>
<FONT face=Arial size=2>In your case, a tested program is a specialized, ‘derived’ or an extended version of a 'program' so would be propagated to it's own relation, along with any other attributes related to 'tested' software... I think you will find that under 2nd Normal Form. </FONT>
<FONT face=Arial size=2>Codd only suggested 3vl logic, the problem was he then found himself suggesting 4vl (true, false, missing, not applicable). Some research went into this and they ended up with 20 reasons for not existent data. </FONT>
<FONT face=Arial size=2>C.Date, H.Darwen, F.Pascal and a few other proponents of the Relational Model rejected 3vl, and if you check the wikipedia entry on Relational Theory / Modeling, the first paragraph rejects the concept of 'Null'.</FONT>
<FONT face=Arial size=2>And yes, SQL is dumb, confused and general not up to the job, and certainly not something I would choose as a ‘Higher authority’
</FONT>
Admin
So... 0 is obviously male then? Looks like a piece of anatomy and 1 looks obviously female.
Or did you mean the other way? I can guess both ways, they're equally likely.
Admin
Then how did you post? You seem to have a funny definition of "entirely nonfunctional".
Admin
Am I the only person who realizes that "the real wtf" is the *entire system*, not those snippets of code? I'm not sure whether Alex or the submitter even intended them to be WTFs on their own.
I think it's constructive to debate the legitimacy of those two excerpts (in fact I learn quite a bit from The Daily WTF by reading through these discussions), but it seems only a handful of people have tried to picture what the entire system might look like. I think a lot of people are failing to realize how terrible the system must be, given that a) we're told it *is* a WTF system, and b) it uses these code snippets -- in horrific ways, no doubt.
Suppose you are a new developer hired to maintain this system. Had the previous authors used an enumeration that was *not* a set of flags, you would know right away that an order can be in at most one of those states at any time (and if you trust them not to WTF-it-up, you know it must be in exactly one of those states at all times).
Instead, we have no idea which flags are mutually-exclusive and which can be on at the same time (comments would have been nice!). It's also possible for the order to be in NONE of those states, i.e. 0. Maybe we can assume that Accepted and Rejected are mutually-exclusive, but would you really feel confident in that assumption given the already-terrible state of the system? ;)
I wonder: is the existence of both Rejected and UnRejected the result of a dev needing a way to determine whether a report is not rejected, and not realizing that they can just use "if (!(status & Rejected))", they made a new flag called UnRejected?
Admin
<!--StartFragment --> no no, I assure you, I know the entire system was a real WTF,
I'll give you a clue on this system..... see the previous WTF, 'yeessssssssssssss noooooooooo' (same place)...
Admin
FILE_NOT_FOUND
Admin
Funny, I actually have a system that has an enum of "male", "female", "unknown". At first when tracking members there were quite a few I'd never met and I hadn't a clue what gender their name even might be. Now I know what gender everybody is, but there are a few members/users that are actually 4-6 people of mixed genders, so they end up as unknown. The mapping of more than one person to a member record is extremely rare, and is not important enough to account for it in all the systems already written. Unknown handles those rare cases already.
Admin
Lol, are you from Earth? 0 is a hole and 1 is a rod. Perhaps the rest of us are missing some clever, different way of looking at it?
Admin
Recently, a lot of experts in the browser field have begun to agree that it's likely that multiple browsers can coexist on a single computer. They say it's probably really complicated, but possible.
Admin
The second-most-highly-paid-consultant's boolean:
enum BOOL {
TRUE,
FALSE,
"NULL"
}