- 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
getList().at(0) is "TRUE" and getList().at(1) is "FALSE"? Yay...
Admin
Well that makes sense. The list allows one to iterate the values of OurBoolean and you never know how many boolean values there will be at compile-time.
Admin
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...
Admin
Additional yay: all variables are strings! That makes it easier to do date processing and conditionals, because true==true confuses me, but "TRUE"=="TRUE" makes sense! yay.
TGIF!
Admin
And imagine how extendable that code is!
Say, you want to port your code to a quantum computer. You just modify the OurBoolean class to return a float in range of [0-1] instead of strings, and you're home!
Admin
1 TRUE 2 "TRUE" 3 "True" 4 "true" 5 FALSE 6 "FALSE" 7 "False" 8 "false" 9 true 10 false 11 Boolean.TRUE 12 Boolean.FALSE 13 "Y" 14 "Yes" 15 "YES" 16 "y" 17 "yes" 18 "N" 19 "No" 20 "NO" 21 "n" 22 FileNotFound
Admin
Everyone knows that "File not found" is 404 in those days. So there have to be at least 405 boolean values. That list starts to make sense to me.
Admin
Don't forget to initialise your list with all possible floats.
Admin
OurBoolean > YourBoolean
Admin
And by calling it OurBoolean, he makes everyone responsible for this gem, not just him.
Admin
Admin
By making it 'Our' boolean he manages to make it sound so much more romantic. It's no longer YourBoolean, its OurBoolean. It's no longer YourCar, its OurCar. It's no longer YourCDs, its OurCDs.
I wonder who will get which half of the Boolean when the relationship breaks down.
Dibs on True!
Admin
I think there might be a problem in that ;)
Admin
Sure there is no problem. If you have a problem with some logical test just switch "TRUE" and "FALSE" in the list and you will have true at(1) and false at(0) changing the outcome. That is just great for testing!
You can even switch them while the program runs. Perfect for debugging and insane fun!
Admin
I also like how getList() isn't thread safe and that they allocate a new String object on every comparison by using toUppercase with equals instead of just using equalsIgnoreCase.
Admin
IPPON!
Admin
The real WTF is that he never used the ArrayList.
Admin
First of all, I don't understand why so many people whant to reinvent the wheel. Maybe they should get a lesson about basic java? Never heard of boolean or Boolean? Very funny, I guess they like doing some hard work over again :-)
And if they absolutely want to create a new Boolean type, they could have used (OurBoolean.TRUE.toUpperCase.equals(result)) instead of (result != null && result.toUpperCase.equals(OurBoolean.TRUE))
they wouldn't have to do a null-check because NullPointerExceptions will be avoid if you change the arguments in the equals method.
Admin
While OurBoolean lacks a "FILE_NOT_FOUND", it looks like you can just add it later if you need it:
OurBoolean.getList().add("FILE NOT FOUND");
Admin
How do you dare to try to improve OurBoolean? It is OUR Boolean, not yours. Go write your own boolean!
Admin
java.util.Collections.reverse(OurBoolean.getList());
Problem solved.
OurBoolean.getList().add("UNKNOWN");
Admin
if(form.userWantsSpam().equals(OurBoolean.getList().at(0) || true){
}
I love it.
Admin
Admin
Admin
Admin
Yes we use this pattern a lot ourselves...
Its great if your client isnt quite sure how they want the values for TRUE and FALSE represented in the GUI....if they change their minds then its simple to just make a change to the code in one place...
Over all this is a Brillant Pattern.
Admin
That would mean that reqult.toUppercase() is always equals to result.
Admin
Considering that this is used to check values from the database, there probably should be one for "NULL".
Admin
good, but you missed out
Admin
I would really like to know just what goes on in the mind of someone who is writing this. I just can't imagine how this could ever come into existence...
Of course, a lot of stuff on The Daily WTF fits that category...
Eyes. Goggles. Nothing.
Admin
Fixed:
What in the world makes you think that the default allocation of <10> is anywhere near enough to store a boolean value?1 TRUE 2 "TRUE", "True", "true" 5 FALSE 6 "FALSE", "False", "false" 9 true 10 false 11 Boolean.TRUE 12 Boolean.FALSE 13 "Y", "Yes, "YES", "y", "yes" 18 "N", "No", "NO", "n", "no" 23 FileNotFound 24 Maybe, MAYBE, maybe 27 Possibly, POSSIBLY, possibly 30 SOMETIMES, Sometimes, sometimes 33 TrueFalse, truefalse, TRUEFALSE, TF, tf 38 VERYTRUE, VeryTrue, verytrue, VT, Vt, vt 44 VERYFALSE, VeryFalse, veryfalse, VF, Vf, vf 50 UNKNOWN, Unknown, unknown, U, u 55 TRYAGAINLATER,TryAgainLater,tryagainlater,TAL,Tal,tal 61 TheFutureIsUnclear 62 SegFault 63 Paula 64 WTF 65 NOTTRUE,NotTrue,nottrue,NT,Nt,nt 71 NOTFALSE,NotFalse,notfalse,NF,Nf,nf
Thanks to all for corrections/ommissions
Admin
Don't forget multiple language support:
23 "S" 24 "s" 25 "SI" 26 "Si" 27 "si" 28 "No[es]" 29 "NO[es]" 30 "no[es]" 31 "n[es]" 32 "Tu es loco, gringo." 33 "O" 34 "o" 35 "Oui" 36 "OUI" 37 "OUi" 38 "oui" 39 "n[fr]" 40 "NON" 41 "Non" 42 "non" 43 "Cochon americain"
Admin
The real WTF is that they used List instead of ArrayList.
Admin
Admin
Hey wait... They DID use ArrayList!!! This code is just fine...
Admin
Admin
Admin
You didn't allow for typos.
Admin
I use to have a bunch of classmates that totally missed the point of having getters, like you show.
Objects were full of "getVector()" and "getList()". I started to argue with them about that, but quickly resigned...
Admin
You left off "flase"
Admin
if result = "true";
then (OurBoolean.TRUE.toUpperCase.equals(result)) becomes ("TRUE".equals("true")), your way fails.
Admin
...just...wow...er...wow
Man this Initrode place is popping up all over the WTFs
Admin
Excuse me ... unless you can provide some proof this is mine, I refuse all responsibility.
This is copied directly from our code, with only the name of the company in the package changed to protect the innocent, not so innocent, and my job.
It's actually used in one place to populate a drop down list for a web page (yes, where 0 = TRUE and 1 = FALSE) but in a dozen places to check if a result is true or false. Where the result is NULL, it's assumed to be FALSE, except where it's assumed to be TRUE.
Admin
You left out a couple:
YEs yES yEs nO
Admin
Not to mention that toUpperCase on OurBoolean.TRUE is, well, kinda silly?
Admin
You also need values like "maybe', "perhaps", "unknown", "half-truth", "ask again later", 0, 1, "Zero", "one", "uno", "Zed" and so on to make this complete.
Admin
I can't believe you left out the Magic 8-ball list:
Admin
don't forget i18n - i bet we could get that list up to the hundreds in no time.
'oui', 'OUI', 'Oui', 'NON', 'non', 'Non', 'Nyet' ...
Admin
Obviously you're not aware of the "time-memory" tradeoff.
Admin
That's what? 2 languages?
Here's two more:
44 "ТАК" 45 "Так" 46 "так" 47 "НІ" 48 "Ні" 49 "ні" 50 "НІЯКИЙ" 51 "Ніякий" 52 "ніякий" 53 "ДА" 54 "Да" 55 "да" 56 "НЕТ" 57 "Нет" 58 "нет"
It looks like Hi and Het, but it is in fact Nie [like knee] and Nyet. Ніякий is left as an exercise for the reader.