Comment On OurBoolean

"While digging through some database code in our system," Paul L wrote in, "I noticed an interesting pattern emerge. Whenever a boolean value within a SQL result was checked, it would look something like this..." [expand full text]
« PrevPage 1 | Page 2Next »

Re: OurBoolean

2008-01-18 08:07 • by Vollhorst (unregistered)
getList().at(0) is "TRUE" and getList().at(1) is "FALSE"? Yay...

Re: OurBoolean

2008-01-18 08:12 • by krupa (unregistered)
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.

Re: OurBoolean

2008-01-18 08:16 • by ThePants999
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

Re: OurBoolean

2008-01-18 08:17 • by sir_flexalot
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!

Re: OurBoolean

2008-01-18 08:20 • by s. (unregistered)
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!

Re: OurBoolean

2008-01-18 08:24 • by snoofle
171776 in reply to 171773
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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

Re: OurBoolean

2008-01-18 08:30 • by Vollhorst (unregistered)
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.

Re: OurBoolean

2008-01-18 08:32 • by An apprentice (unregistered)
171778 in reply to 171775
s.:
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!


Don't forget to initialise your list with all possible floats.

Re: OurBoolean

2008-01-18 08:36 • by akatherder
OurBoolean > YourBoolean

Re: OurBoolean

2008-01-18 08:41 • by gabba
And by calling it OurBoolean, he makes everyone responsible for this gem, not just him.

Re: OurBoolean

2008-01-18 08:41 • by Joe Luser
171781 in reply to 171777
Vollhorst:
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.

TEH WINNAR!!!

Re: OurBoolean

2008-01-18 08:50 • by yet another Matt
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!

Re: OurBoolean

2008-01-18 08:52 • by StarLite (unregistered)
171783 in reply to 171778
An apprentice:
s.:
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!


Don't forget to initialise your list with all possible floats.

That might take while, but that shouldn;t be a problem for the quantum computer to do automatically.
You'd first need to write a program for that tho, which will have toinclude OurBoolean, which will have to be initialized bij a quantum computer, which will need a program that...

I think there might be a problem in that ;)

Re: OurBoolean

2008-01-18 09:00 • by Vollhorst (unregistered)
171784 in reply to 171783
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!

Re: OurBoolean

2008-01-18 09:05 • by Someone (unregistered)
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.

Re: OurBoolean

2008-01-18 09:11 • by sweavo (unregistered)
171787 in reply to 171776
snoofle:
What in the world makes you think that the default allocation of <10> is anywhere near enough to store a boolean value?


IPPON!

Re: OurBoolean

2008-01-18 09:15 • by MA (unregistered)
The real WTF is that he never used the ArrayList.

Re: OurBoolean

2008-01-18 09:20 • by SoulReaver (unregistered)
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.

Re: OurBoolean

2008-01-18 09:29 • by JL (unregistered)
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");

Re: OurBoolean

2008-01-18 09:30 • by Vollhorst (unregistered)
171793 in reply to 171789
SoulReaver:
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.


How do you dare to try to improve OurBoolean? It is OUR Boolean, not yours. Go write your own boolean!

Re: OurBoolean

2008-01-18 09:33 • by Tom Hawtin (unregistered)
171794 in reply to 171771
Vollhorst:
getList().at(0) is "TRUE" and getList().at(1) is "FALSE"? Yay...


java.util.Collections.reverse(OurBoolean.getList());

Problem solved.

OurBoolean.getList().add("UNKNOWN");

Re: OurBoolean

2008-01-18 09:35 • by Vollhorst (unregistered)
171795 in reply to 171794
Tom Hawtin:
Vollhorst:
getList().at(0) is "TRUE" and getList().at(1) is "FALSE"? Yay...


java.util.Collections.reverse(OurBoolean.getList());

Problem solved.
You just fucked up the whole system. It depends on False being on the first/zeroth position.

if(form.userWantsSpam().equals(OurBoolean.getList().at(0) || true){

}

I love it.

Re: OurBoolean

2008-01-18 09:36 • by DaveK
171796 in reply to 171776
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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
You got FILE_NOT_FOUND, I see, but you left out VERYTRUE and VERYFALSE.

Re: OurBoolean

2008-01-18 09:39 • by DaveK
171798 in reply to 171796
DaveK:
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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
You got FILE_NOT_FOUND, I see, but you left out VERYTRUE and VERYFALSE.
Gahh. And *I* forgot FAIRLYTRUE and FAIRLYFALSE. D'oh!

Re: OurBoolean

2008-01-18 09:41 • by DOA
171800 in reply to 171796
DaveK:
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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
You got FILE_NOT_FOUND, I see, but you left out VERYTRUE and VERYFALSE.

Also UNKNOWN, MAYBE, SEG_FAULT, THE_FUTURE_IS_UNCLEAR, TRY_AGAIN_LATER and PAULA

Re: OurBoolean

2008-01-18 09:54 • by Paula Bean (unregistered)
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.

Re: OurBoolean

2008-01-18 09:58 • by sdfsqdfqsdfsqdf (unregistered)
171803 in reply to 171789
SoulReaver:
they could have used (OurBoolean.TRUE.toUpperCase.equals(result)) instead of (result != null && result.toUpperCase.equals(OurBoolean.TRUE))


That would mean that reqult.toUppercase() is always equals to result.

Re: OurBoolean

2008-01-18 10:10 • by Licky Lindsay
Considering that this is used to check values from the database, there probably should be one for "NULL".

Re: OurBoolean

2008-01-18 10:30 • by Phil (unregistered)
171813 in reply to 171776
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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



good, but you missed out

23. TrueFalse

Re: OurBoolean

2008-01-18 10:35 • by SomeCoder (unregistered)
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.

Re: OurBoolean

2008-01-18 10:42 • by snoofle
171818 in reply to 171813
Fixed:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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

Re: OurBoolean

2008-01-18 10:43 • by G Money (unregistered)
171819 in reply to 171776
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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


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"

Re: OurBoolean

2008-01-18 10:59 • by El Dudarino (unregistered)
The real WTF is that they used List instead of ArrayList.

Re: OurBoolean

2008-01-18 11:03 • by snoofle
171833 in reply to 171819
G Money:
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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


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"

*shudders*

Re: OurBoolean

2008-01-18 11:04 • by El Dudarino (unregistered)
171834 in reply to 171829
El Dudarino:
The real WTF is that they used List instead of ArrayList.


Hey wait... They DID use ArrayList!!! This code is just fine...

Re: OurBoolean

2008-01-18 11:05 • by snoofle
171837 in reply to 171829
El Dudarino:
The real WTF is that they used List instead of ArrayList.

There's nothing wrong with returning the interface to an object instead of the object itself. It's the one thing in that code that's NOT a wtf!

Re: OurBoolean

2008-01-18 11:05 • by brazzy
171838 in reply to 171829
El Dudarino:
The real WTF is that they used List instead of ArrayList.

You mean because such obviously idiotical programmers managed to get one thing right?

Re: OurBoolean

2008-01-18 11:07 • by Bob (unregistered)
171840 in reply to 171776
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
3 "True"
4 "tr...


You didn't allow for typos.

Re: OurBoolean

2008-01-18 11:09 • by Philippe (unregistered)
171841 in reply to 171792
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...

Re: OurBoolean

2008-01-18 11:09 • by Bob (unregistered)
171842 in reply to 171776
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

What in the world makes you think that the default allocation of <10> is anywhere near enough to store a boolean value?


You left off "flase"

Re: OurBoolean

2008-01-18 11:16 • by Michael (unregistered)
171844 in reply to 171789
SoulReaver:
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))


if result = "true";

then (OurBoolean.TRUE.toUpperCase.equals(result)) becomes ("TRUE".equals("true")), your way fails.

Re: OurBoolean

2008-01-18 11:30 • by Militis Sanctus (unregistered)
...just...wow...er...wow

Man this Initrode place is popping up all over the WTFs

Re: OurBoolean

2008-01-18 11:30 • by Paul L (unregistered)
171854 in reply to 171780
gabba:
And by calling it OurBoolean, he makes everyone responsible for this gem, not just him.


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.

Re: OurBoolean

2008-01-18 11:33 • by BinaryPhalanx (unregistered)
171857 in reply to 171776
You left out a couple:

YEs
yES
yEs
nO

Re: OurBoolean

2008-01-18 11:34 • by wgh
171858 in reply to 171844
Michael:
SoulReaver:
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))


if result = "true";

then (OurBoolean.TRUE.toUpperCase.equals(result)) becomes ("TRUE".equals("true")), your way fails.


Not to mention that toUpperCase on OurBoolean.TRUE is, well, kinda silly?

Re: OurBoolean

2008-01-18 11:50 • by Harry (unregistered)
171866 in reply to 171776
snoofle:
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...

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"
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


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.

Re: OurBoolean

2008-01-18 12:21 • by rycamor (unregistered)
171873 in reply to 171818
I can't believe you left out the Magic 8-ball list:

● As I see it, yes
● Ask again later
● Better not tell you now
● Cannot predict now
● Concentrate and ask again
● Don't count on it
● It is certain
● It is decidedly so
● Most likely
● My reply is no
● My sources say no
● Outlook good
● Outlook not so good
● Reply hazy, try again
● Signs point to yes
● Very doubtful
● Without a doubt
● Yes
● Yes - definitely
● You may rely on it

Re: OurBoolean

2008-01-18 12:25 • by kwilliaa (unregistered)
171874 in reply to 171776
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'
...

Re: OurBoolean

2008-01-18 12:49 • by savar
171888 in reply to 171773
ThePants999:
It "optimizes for memory usage" by creating a 10-element list to hold boolean values...


Obviously you're not aware of the "time-memory" tradeoff.

Re: OurBoolean

2008-01-18 12:49 • by ChZEROHag
171889 in reply to 171819
G Money:

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"


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.
« PrevPage 1 | Page 2Next »

Add Comment