- 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 tried the rock music thing for a few years back in the 80's. We did ok but you would never know about us now. The point here though, is that the models we attained were more of the penthouse variety, moderately good looking, easy, and came with free pizza and beer. The order of importance of those three factors varied greatly from one day to the next.
Admin
From the article: "For a class that has a value of either yes or no." That sounds awfully like a boolean value to me.
Also, get it straight, the developer (who is anonymous) is not up for ridicule. His or her heavily over-engineered code is up for ridicule, because it is, well, ridiculous.
Even if you've got ample reason to do this sort of thing, (you need a custom ORM solution for your database, you need to process documents in multiple languages, etc.) there are much better ways than rolling your own. For example, Spring:
http://www.springframework.org/
Every Java programmer should get familiar with Spring. If you don't see any use for it, congratulations, your code will probably be featured on this site in the future. If you do see a use for it, you'll remember the day you read about this library on WTF, and how cool it was to find something so damn useful it hurts.
CAPTCHA: scooter (should have served jail time!)
Admin
Classes don't store values?! Did you forget what web site you're on? Around here, it's generally expected behavior for classes to store values. Its best to create a new class every time you want a new value.
For example (untested):
Admin
Or, you're supremely lucky enough to never have to develop in Java.
/and nobody gives a flying failure what your failing CAPTCHA is
Admin
Where's the unit tests?
Admin
Since the result of YesNoFactory.getFactoryInstance().YES.getDescription().equals(array[0].toUpperCase()); is a String of length one that respresents Yes or No, this is completely conformed and ready for XML. That makes it fully Enterprise-ready!!!!
Admin
"YesNoFactory.getFactoryInstance().YES..."
Anyone else notice that this expression does not even call a method of the factory at all? It appears to be using an instance reference to refer to a constant (public static final) value defined in the YesNoFactory interface or class. So the factory is entirely pointless.
Admin
Actually, I love such 'three-state booleans', be it 'null', 'undef', '!isset' or whatever the language provides as the third state. The three states are "TRUE", "FALSE" and "DON'T TOUCH THE FUCKING DEFAULT". Makes passing boolean parameters down the inheritance tree much more convenient.
Admin
You are definitely one of my top nominees for humanities greatest WTF ever prepared!
Congrats!
Admin
No clue if that's the case here, but saying "classes don't store values, their instances do" is wrong.
Admin
God help us all.
Admin
Admin
I'd laugh if it wasn't for the fact I just spent the last couple of months purging this same kind of drivel from the code base I have inherited in my current contract.
Admin
Your faith in my guitar playing is touching. Misplaced, but touching.
I like to tell people that I play a unique style of music where I take well-known songs and play them REALLY slowly and make lots of mistakes...
I also point out that if I could get someone to pay me what I make as a programmer to practice the guitar for 8 hours a day (plus emergency off-hours/weekend work), I'd be Steve Freakin' Vai by now. :)
Admin
If you don't develop in Java, you don't know what you're missing.
Admin
I use Booleans to represent 3 values - true, false, and I don't care.
captcha: what a tastey morsel.
Admin
We could probably take a pretty good guess.
Admin
Admin
Um, what? First of all, you think enums being objects are a WTF? I imagine you'd hate SimpleTalk, in which everything (even numbers) were objects.
Second of all, I fail to see how allowing an enum to be null breaks the entire concept, or at least for the example you gave. Of course you can't invoke methods on a null object - so what? You can't invoke methods on a null pointer in C++ either; does that make them broken?
I haven't done much work with Enums in Java, so I don't know a whole lot, but you sure haven't convinced me they are broken.
Admin
Whipped up some quick prototype code and spent all day banging my head against the wall debugging it. See, our program uses different kinds of connectors, and consequently different kinds of pools of said connectors. I was adding a new connector (so copy/pasted QueueConnector and modified it slightly) and a new Pool (so copy/pasted FilePool and modified it slightly).... The reason it was broken all day?
Now the guy who originally coded it is trying to convince me that there's a reason to have two different kinds of bools.
"truth is in the abstract base class of the beholder thread" i guess.
Admin
There's other issues in what you've quoted, but I'll leave them for others to notice.
Admin
That was my first thought too - code generation. Nothing like a good ole' code generator to churn out thousands of lines of code. Doesn't really matter until you have to modify by hand.
Admin
captcha test
Admin
For those who have had to deal with inappropriate factories and haven't read this already: Why I Hate Frameworks. A very funny article on 'Joel on Software' about frameworks and their factories.
Admin
Except neither functions nor structs are just syntactic sugar. You can't store labels into variables nor cast random pointers to whatever types without alignment issues.
Admin
The real WTF is using Java to do anything at all. It's a sh|t language.
Admin
Exactly right my friend. That's what the so-called experts here don't seem to realise. You can't have a true WTF unless it eats bread.
BTW, whatever you're smoking, save some for me.
Admin
And it doesnt even handle FileNotFound...
Admin
CAPTCHA: digdug
Admin
The author should be taken outside and poked with sharp wooden sticks until they repent of their sin.
It's so bad it's not even funny; if some who worked for me came up with a 'solution' like that I'd seriously consider firing them.
I saw something similar once-upon-a-while; for a gas metering system, a Premises class had a Meter class, which had a Dial class that had an ordered collection class of Digit classes each of which had a Value property...
Admin
I'm not sure I even know what mr. anon is saying - is he suggesting that MyEnumClass.AN_ENUM_VALUE can be null? How? Or does he just mean that a reference variable of enum type can be null at runtime? The latter is obviously true. How would you prevent it? The compiler can't detect possible NullPointerException-s before they happen.
(And, btw, let's have no more talk about "null objects" unless we mean the Null Object Pattern. "null" in Java isn't an Object.)
Admin
The 'author' was almost certainly a code generation tool. Those things are hard to poke with sticks.
Admin
If the value hasn't been initialized, you can't assume it means anything. Just throw a runtime exception because you are in an invalid state and move on with your life.
Now of course if you just use lower case booleans, Java enforces this for you by requiring them to be initialized before it ever gets used. Upper case Booleans are just intended to be wrappers for those primitives so that they can be used in things that only take Objects such as collection classes.
Admin
Actually you are wrong. If you are working with a true boolean state and you see one that is not initialized then you can and should the default safe state and continue. If you can not assume a safe state you are not working with a boolean.
I gave two examples of valid booleans that you can assume a state with, now let's think of one that many people incorrectly assume they can use a boolean for, gender. If you assume 1 is male and 0 is female and you see an uninitialized gender variable, what is the safe decision? There is none. This is a third state and therefore not a boolean which is defined as two state. So you now have Male Female and unspecified.
How you handle the unspecified is up to the application, some may raise an error if this info is required, some may accept the unspecified state as a valid value and assume this state. It still is not a boolean. Simply throwing an exception is not always the right decision, sometimes it is, but not always. You can sometimes make assumptions about missing data that will always be correct.
Admin
For the life of me, I cannot think of something like that. I mean it takes balls and brains to even imagine such a convoluted strange and overly complex system.
Admin
In the C++ program I work with we have scads of code to deal with booleans. We make a debugger. We need to read the binary files and interact with dozens of different versions of compilers. It turns out that for C and C++ the underlying data type for boolean may be signed or unsigned, but there is not a lot of other choices. For Fortran, the representation of True and False are not standardized. Sometimes 0 is false, 1 is true and everything else is undefined. Sometimes -1 is true, sometimes -1 is false. This can all happen on the same system, but with different compilers.
So, if this is a code from a Java implementation of a Fortran debugger, it might very well need more than 150 lines of code do do the right thing. Unless you can see the code, and you know what it's there for, you can't tell if it's right or wrong.
Admin
No it doesn't.
When dealing with Boolean objects, null means null. OTOH, the boolean primitive is false if not explicitly set.
HTH.
Admin
Please read my statements above. With boolean objects null = the safe assumption. If there is no safe assumption and you retain the null you now have a third value to consider, it is no longer a boolean but now a three state enum.
Admin
I thought about this initially thinking it wouldn't matter because if you compiled the application it knows what is true or false and checking the value with a if(booleanVar) would always return correctly. Then I thought about multiple systems interacting and therein lies the problem. The lack of standards can make this a problem.
Admin
No way. null means FileNotFound. DUH.
Admin
The real WTF is that the bool return of .equals() isn't being converted back to a YesNo instance.
Admin
I dunno. Looks pretty standard... for Java.
Admin
It looks like it was probably spit out by some code generator. I would rather have this than to have to treat this entity different than all the other generated entities.
Admin
The real WTF are all the people that think this isn't a work of fiction.
Admin
Boolean is the wrapper class for boolean primitives.
CAPTCHA: onomatopoeia. No stupid joke, just a whinge about insanely long CAPTCHAs
Admin
javac (the Sun Java compiler) seems to give a compiler error if it thinks it is possible that a variable may be initialised before use. With a Boolean object, if it is uninitialised, you get a NullPointerException, with a boolean primitive, you get a compiler error. 0 does not evaluate to false in Java, and you cannot use: [code}int foo= 42; if(foo)[/code] although a null object does evaluate to false.
In some cases it will warn even if it is impossible for the variable to be uninitialised: for example:
was rejected by the compiler, presumably because it did not realise that there was no way that you could I was not allowed to write if(foo=...) by the coding standards for the course I was studying, and there was a good reason at the time for not setting foo outside the if-statement beforehand
Admin
Static fields (not properties, not in Java) are stored in the class, and pointed to by the instances.
Admin
Looks more like an "effluent" interface to me...
Admin
Admin
You can't even create a Java List<int>. Instead it becomes a List<Integer> at compile time and then a List at runtime because Java doesn't really support generics.
If you want to see generics done right, look at C#. If you want to see generics turned into worthless syntactic sugar than can allow you to stick Booleans into a list of Strings simply by disabling warnings, look at Java.