- 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
I really want to say something about how true would obviously be male, and false would be female...but I'm afraid some of you might think I'm being sexist. So I won't say anything at all.
-ds
Admin
I'm using FF 1.5.0.1 and it works like a champ. When I was on 1.0 it also worked nicely.
Admin
I guess this has to do with teh appearance of the 1 and 0. One of them is obviously more of a phalic symbole then the other. Of course this could be the root cuase of many fallicies.
Admin
The best part about this is that enums start at 0 (at least in C and C++, not sure about C#). So TRUE is false and FALSE and NOT_TRUE_OR_FALSE are true.
Admin
Yeah, so? If the abstraction is adhered to, it's fine. In fact, unix programs use the same convention in their return values:
0
$ false ; echo $?
1
There are plenty of other programming languages that don't adhere to the 1==true, 0==false method (LISP, for example).
Admin
The bitmask is not a WTF by any means. It might not be the absolute best way to do it, but often in procurement or inventory control things can be in multiple states simultaneously. Now, there may be conflicting states in this particular bitmask, but that's impossible to know without seeing the actual business case. Yes, there are crazy bean counters to whom having an order in the state Rejected | Approved | PendingApproval may just make sense. It could concievably be an order that was approved by some, rejected by others and waiting on some more people, so it goes into 3 categories and your logic goes like:
forEach(order where orderStatus & Approved)
if(orderStatus & PendingApproval) break; // Not everyone has given their say
else if(orderStatus & Rejected) sendToNegotiation();
else processApproval();
Admin
"So:
Straight Enumerator for mutually exclusive values.
Bitflags for concurrent state values."
I think it depends on the scope of what you're talking about. I have a situation in which in the BPL the types are exclusive, but for reporting purposes I need to be able to group combinations of types on-the-fly. As long as you enforce exclusivity in the proper places it shouldn't be a problem.
Admin
not necessarily. Say that there is a time limit to approve/reject something. If you don't approve or reject within the time limit, then a default action takes place. So this way, you could always go back and see whether the person actually approved/rejected it or it was just not acted upon and the default action happened.
My WTF ruling is: Not_True_Or_False ie need more information
Admin
Heaven, Hell, Purgatory
Admin
He one-upped me. He actually read the boolean algebra post. I was just going to say "lets look at the definition for boolean"
http://en.wikipedia.org/wiki/Boolean
Admin
It can quite happily have more than two elements, though, as some of the examples on that page show.
Admin
Tri-state bools are nothing new.... databases have returned null for a bool column for decades now. IMO, the only WTF there is that he's using C#, but not using C#/.NET 2.0 and nullable types, which *does* support a tri-state bool. In a way.
http://msdn.microsoft.com/vcsharp/2005/overview/language/nullabletypes/
No, my big WTF is the first enum. Why specify powers of 2 values, but no [Flags] attribute? If the [Flags] attribute was unintentionally left off (either by the author of this WTF article, or by the original code author), and it's intended to be a bit flag, why are there so many states that cannot possibly be valid together? Rejected & UnRejected, for example. UnRejected itself is a huge WTF. Also, what does Reject mean that Rejected doesn't handle?
Admin
<font size="2">why do all this, when you can:
String foo = new Storray( status = UnRejected ).ToString().ToString();
if(!foo != NOT_TRUE_OR_FALSE){
System.out(foo).ToString();
System.out( "Paula is Brillant!" + foo );
} else {
System.out( "Please Compile!" );
System.out( "Paula is Brillant!" + foo );
}
</font>
Admin
phallicies?
Admin
It's a WTF to call it a BOOL.
Admin
It's just missing the PendingRejection status.
Admin
You usually link a page that supports your assertion, not one that contradicts it.
Admin
is z "I don't want to know" ?
Admin
I love it. Schitzophrenic orders that can be both Approved and also Rejected (4 | 128).
Yay!
Admin
Admin
Not quite. Check the MS docs for GetMessage() sometime. Tri-state BOOL from the mid-nineties.
Admin
There's a difference between requiring two distinguished elements and allowing only two elements.
The page has 6 examples of Boolean algebras with more than 2 elements, including one with a diagram.
Admin
Gender is not the appropriate situation to apply boolean logic. Chromosomally speaking, you can be boolean (presense or abscense) minded when talking about whether a Y chromosome on the sex gene exists, but in terms of physical appearance and culture, you could be dealing with an indivudual who is intersex could be classified as (Gender.MALE | Gender.FEMALE), depending on how the individual feels that day and where in his/her life (s)he is in before (optional) gender-correction surgery.
The moral of the store is, use an enum here and put the options you need. I would disagree with using NULL instead of an Other/Intersex value, as if you removed the person's undergarments there definately isn't NULL going on down there. This situation occurs naturally in the population at large.
Hope that cleared things up.
Admin
Yes, it would allow that. It's really pretty well done, I don't see a WTF at all. Thats someone with alot of experience to know to setup an enum to allow bitwise logic like that.
The only wtf here is that bool enum which is named bool. If he needed those three option he should have called it something else, like "FuzzyBool" or something.
Admin
Personally I don't see the problem with the first enumeration, that is , if that enumeration is to represent discrete states an order can be in. I doubt it was meant to be used as a bitmask.
For example, perhaps some condition must be true for an order to move from Opened to PendingApproval. They are simply workflow states, not to be combined -- as many of you mentioned, that would be the work of a dumbass.
As for the "tri-state Boolean" enumeration, George Boole himself came up with our concept of on-off, yes-no, stick-circle or whatever kind of logic you may call it. There is no room in his popular work for a third state. Therefore, any attempt to "extend" Boolean logic to include a ternary state is also the work of a dumbass. Including nullable bools.
Some people would say that a light can be on, off, or dimmed. But that's wrong. If it's dimmed, it's on. There is just another variable to say how bright the light is.
See you in the bar,
Ribbly
Admin
Normally I shake my head in disbelief at the WTFs posted on this site, but this isn't one of them. For example, I could envision a separate order status for reject (order is slated to be rejected), rejected (order has already been rejected) and unrejected (was rejected once, but was overridden and restored). And as others have mentioned, the fact that databases allow nulls means True/False/Unknown (or whatever you would like to call the third state) actually makes sense.
No Digg.
Admin
WTH
I vote for least WTF ever on this forum.
Almost to the degree of arguing - this is not a WTF.
Admin
What I love is that you could have an OrderStatus value of 1152, which would be both Rejected and UnRejected....
Admin
It's called Flag Enum for use with bit-wise operators. It's a very good practice. The names like Reject, Rejected, Deleted, Removed, UnRejected = 1024 are the WTF.
I am a rejected reject that was deleted removed, and unrejected... oh yeah, and I was approved. [:^)]
Admin
it's things like this that make software maintenance fun
Admin
Indeed. And, in fact, the C++ Boost library specifically provides a tribool type. Of course, its semantics are well-defined. Perhaps this is less so here.
Admin
As for circuit simulation, HIGH (1), LOW(0), UNKNOWN(X), RISING(U), FALLING(D) would have 5 states already - and that's what we use to build up our good old boolean systems in reality [<:o)]
Admin
Not to mention odd ball cases like XXY and other naturally occuring genetic situations.
Admin
I've seen this comment (or renditions of it several times) and my problem with this assumption is that if you state a column in SQL (or any other db, i hope) as a Boolean you would want two states, the definition of boolean. Therefore it would be true or false, and you would add NOT NULL to the column definition. Therefore for gender if you desired to have two columns of bool for male and female, the unknow state would be both false, if both are true well...
I'm guessing that if it's a db backend problem the definition of the columns is incorrect.
remember...
Admin
Male, female, intersexed, transsexual, unknown, not sure....
Admin
Why stop there?
public enum BOOL-BALL
{
TRUE,
FALSE,
MOST_LIKELY,
MY_SOURCES_SAY_FALSE,
SIGNS_POINT_TO_TRUE,
TRUE_DEFINITELY,
OUTLOOK_TRUE,
OUTLOOK_NOT_SO_TRUE,
REPLY_HAZY_TRY_AGAIN
}
Admin
More like the root cause of many phalluses
Admin
I read this and now I can't touch power buttons anymore.
Admin
Ahh, looks like my prior input sequence just pissed off the interface. Try hitting the reply button, then (without entering any text), hit the "HTML" tab. Then click back to the "design" tab. Now type something. Now try your arrow keys. . . Or try to post what you typed .
Admin
I'm surprised that a number of posters are defending this bit of code. There are two possible ways that this enum will be used:
Bitmask. Status = 132 means Approved and Rejected. Um, yeah. Status = 32 means PaidFor but not Opened or Approved. Er.... These don't seem like sensible states for a bitmask.
Single state. Status = 4 means Approved and Status = 128 means rejected. Okay, but why didn't you just use 1, 2, 3 instead of powers of 2 for the values? And if Status has a single state, then what does UnRejected mean? Don't we need to be able to say that an order is UnRejected and Approved, or UnRejected and PaidFor?
This is the very definition of a WTF. I look at the enum and say "WTF is it supposed to do?".
AlpineR
Admin
Figuring out gender can be quite a puzzle.
I'm *VERY* used to being thought female--the male version of my name is so uncommon that people think it's a variant spelling on the female version.
Admin
I believe this would be absolutely NOT_TRUE_OR_FALSE.
Admin
Are you that sure? And what do you put in your database when you don't know the state of a field, or the field just doesn't apply? Want an example? A list of software where each entry has a "working" field, meaning "does this program work?" Obviously, a program can either be working or not... but what if you haven't tested it yet?
But you appealed to a higher authority. Let me appeal to several others: the creators of all those SQL databases out there. According to you, they're all dumbasses, right? And you must be Edgar Codd himself? Oh wait, you can't be. Codd's 3rd rule explicitly says "The DBMS must allow each field to remain null (or empty). [...]" (see on Wikipedia).
<personal:rant>I have a biiig problem with people who argue an issue though they haven't read one bit about it, or at least talked to someone familiar with the matter. Naturally, when invited to do so, they usually refuse. I guess changing opinions is exceedingly difficult to some people. Living in one's own fantasy world and all that...</personal:rant>
Admin
Everyone talking about the [Flags] Attribute got me looking it up, because I've done bitwise enums before without it... I assume everyone is talking about the [FlagsAttribute] Attribute :) And while it does look nice, there's nothing stopping one from using a straight enum. It just requires you explictly casting to an int and then back to the enum type, ie:
if(Convert.ToBoolean((this.Order.CurrentOrderStatus & (int)OrdersProg.OrderStatus.Open)){ /do something/ }
Admin
So you have found a bug. It is hardly "You know, this forum software is pretty much entirely nonfunctional with Firefox." That is a typical end user behaviour and not a good one. "Physician, heal thyself."
Sincerely,
Gene Wirchenko
Admin
Like booleans, enums can be abused, too.
Status, the one-word summarization of the state of an object, is a tricky area. It's often (over)used in the indication of an object within some sort of defined lifecycle, but the process within the lifecycle grows like an amoeba.
Thus, you create a problem where the users start to create many statuses in order to dileneate and seperate workload, when you really should have created a container structure (like seperating queues) to represent the workflow state or used some external business rules engine (or roll your own) to handle the changes.
Say you have a new system for handling incoming medical claims. You start off handling incoming claims with these statuses:
New
In-Adjudication
Discarded
Approved
Pending Payment
Paid
Denied
Simple, right? For 100 claims a day probably so. But, like email, it's going to be organized differently when the volume goes up and probably some automatic distribution code will be added to help seperate the workload. If you come back to the system in a year you'll probably see some statuses like these:
New - Unassigned
New - Region A
New - Region B
New - Region C
New - Large Claims
Discarded
Hold
In-Adjudication
Adjudication Pending (Fraud Review)
Adj. Pending (Audit)
QC - Wait
QC
Approved To Pay
Approved To Split
Pending Payment - Cincinatti
Pending Payment - Direct Pay
Paid
Denied Full
Denied Partial
Denied - Appeal Filed
Reopen
Within 3 years you'll see a bunch of dead statuses and all sorts of non-descript meanings attatched to others. When it comes to a status that indicates the state of something within a WORKFLOW, then the best idea is to wrap the object in a container which you can change (like mail within a folder or a file within a directory).
Like mail, mail objects can be reorganized if you have folders to organize them in. You can also create rules in code or with external vendor app help to automate the process of moving the objects around within the containers.
Healthcare claims typically have at least 10 different "statuses". The healthcare provider (your hospital) might have different statuses for how complete the claim is, and where in the electronic filing process the claim is in, where in the payment cycle process the claim is, and if the claim was denied, where in the legal process the claim is in. A payer (your HMO) keeps track of where in pre-adjudication the claim is in, where in the remittance process the claim is in, where in the appeals process the claim is in, and so on.
Enums are a quick-n-dirty, but if you change the process a lot, you will be living with a data-shuffling nightmare as the workflow changes.
Admin
Actually... a qubit would be measured as true, false, or both. Not true, false, or neither. So I don't know what this could be.
Admin
Agreed, it's not unheard-of to have tri-state logic "true / false / unknown" as a lot of people point out... but "unknown" is a far cry conceptually from being "neither true or false"! Or as my co-worker interpreted it, (! TRUE) || FALSE, which would be basically equivalent to false. Just weird is all. I don't see the usefulness.
Admin
It seems that the OrderStatus flags mark some kind of workflow milestones. The order would progress through different stages, setting just one bit at every stage. Then, when you want to select or count orders in a given state, you just search for (Orders.Status & PaidFor.!= 0).
Of course, the WTF is that this is the poor man's relational model, when they should have created a separate table for tracking an order's progress through the system.
As for the BOOL construct, the modern C# 2.0 has just the equivalent: the 'bool?' type, which holds values of true, false and null (just like a field in a database). The NOT_TRUE_OR_FALSE usually means 'we don't know', 'not applicable', or 'who gives a sh*t'.
Admin
While I haven't seen the business logic I don't see anything inherently wrong with the bitmap.
The tri-state boolean, though! I have no problem with such tri-states and have even implemented a few over the years. Pick better names, though! I summed it up pretty well in some long-ago documentation: The computer won't care if the key for a wall cabinet is "BASE" but the users sure will!