Comment On The Green, the Whole Green, and Nothing But the Green

Relational databases don't have Boolean data types for good reason: the inherent nature of tri-value logic (i.e., true, false, and unknown/null) makes it a logical impossibility. To compensate for this, developers will use a code of some sort to represent their data: 1/0, 'T'/'F', 'Y'/'N', or, in D.P.'s case, "green"/"red". [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:18 • by uncool
looks like someone really liked the game 'red light green light'

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:18 • by Robert Carr
*shudders*

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:23 • by diaphanein
57168 in reply to 57167

Usually, I think people jump the gun when claiming code is generated, but for once I actually do think this was generated.  Rather moronically of course.


Alternatively, the original other was just exercising premature optimization (think loop unrolling), which is, of course, the mother of all f***-ups.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:29 • by zip

Yeah, I've always been confused by when to use loops...

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:30 • by CornedBee
Uhm ... I think BOOL or BOOLEAN is a standard SQL type, and even if not, quite a few RDBMSs have it: Postgres, MySQL (as an alias for TINYINT), I'm sure there are more.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:32 • by limelight
I love how the presentation and data layers have been blended together. Image you are tasked with adding/removing a page.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:33 • by LuciferSam
Boolean values are over used anyways.  The flexibility of a character or string type is much preferred.

example: Why use just True or False when one could use, 1, 0, T, F, Y, N, null, FileNotFound, and Purple all as valid values!


/sarcasim

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:33 • by Tom the Quantum Computing Guy
Is there any chance the green/red might relate to the checked/unchecked
image in the ImageUrl?  I know it's common among developers to
display a green checkmark to indicate a valid result whereas a red X is
used to indicate an invalid result.  Not that this excuses the
rest of the code's structure but it may somewhat explain the
developer's thinking in regards to the red/green boolean logic.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:35 • by Maz

But .Net has booleans! and they're not even red and green!


*CRIES*

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:38 • by Gene Wirchenko
Alex Papadimoulis:
Relational databases don't have Boolean data types for good reason: the inherent nature of tri-value logic (i.e., true, false, and unknown/null) makes it a logical impossibility.


This statement is a WTF itself.  If you require tristate logic, then do not use binary logic.  This is much the same as selecting a fixed decimal type when representing currency instead of using integers.  Pick the appropriate type.

Some DBMSs do not have boolean.  Some do.

Sincerely,

Gene Wirchenko

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:40 • by boohiss
I don't think SQL Server has boolean, but it does have a 'bit' data type, which can be 1/0 (of course).

ASP (at least) interprets the bits as "True" or "False" in an ADO recordset.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:40 • by GoatCheez
57178 in reply to 57174
Anonymous:
Is there any chance the green/red might relate to the checked/unchecked
image in the ImageUrl?  I know it's common among developers to
display a green checkmark to indicate a valid result whereas a red X is
used to indicate an invalid result.  Not that this excuses the
rest of the code's structure but it may somewhat explain the
developer's thinking in regards to the red/green boolean logic.


Naw man. d00d was totally feeling the Christmas spirit when he coded this lump of shit.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:40 • by Disgruntled DBA
Great!  Now I have this song running through my head.  Someone please feed me to the giant man-eating Iranian cockroaches, so I can find some comfort!


http://www.pythonland.com/song25.php

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 14:49 • by ferrengi
Ummm, what the hell is this?

Is the content for each of the webpages being stored on the database?

Each page has it's own Content, Title and IsComplete column? If they are all completed, the form can be submitted?



Assuming I got all that right, a few questions for the "developer":



1) How come Is_Complete_Page1 and IsComplete_Page25 are varchar(15) but IsComplete_Page2 is varchar(10)?

At least if you are going to royally screw up, be consistent!



2) Also, since these Is_Complete columns only have values of "green" or
"red" (or maybe "null" since they have to put something in there
because the column is defined as NOT NULL, which is also stupid. The
content and title can be NULL but Is_Complete must have a value!
WTF?!). Anyway, I digress, why does the column need to be varchar(15),
what's wrong with varchar(5)?

Not that he would care anyway because it could easily have been stored
as char(1), 'G' or 'R' or better yet 'Y' or 'N' (on second thought,
that would be too easy).

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:00 • by JS
I use the bit datatype for booleans in SQL Server.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:01 • by mrsticks1982

I say it was coded by a monkey!!!


 


Bring back Gorillaz!!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:02 • by mrsticks1982
57185 in reply to 57183

Anonymous:
I use the bit datatype for booleans in SQL Server.


 


me too! but that makes to much sense?!?!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:08 • by LaurieF

But why isn't it in third-normal form? It's just wrong. [8o|]


Codd is spinning in his grave.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:11 • by BlackTigerX
57187 in reply to 57186
I think I know the guy who wrote that...[+o(]

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:14 • by Dave L
If they replace true and false with #00ff00 and #ff0000 then I'll be impressed.

Of course when they come across #ffff00 then they're fucked!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:16 • by JuJuBe
"Relational databases don't have Boolean
data types for good reason: the inherent nature of tri-value logic
(i.e., true, false, and unknown/null) makes it a logical impossibility."

Seriously, what?

Are you serious? A boolean is now a tri-value? Wow.

http://www.postgresql.org/docs/7.4/interactive/datatype-boolean.html
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

Anyway, yes, using Green/Red is kinda dumb, but no dumber than saying boolean is a 'tri-value'.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:17 • by Gene Wirchenko
57190 in reply to 57186
LaurieF:
But why isn't it in third-normal form? It's just wrong. [8o|]

Codd is spinning in his grave.

I doubt it.  If he were, given the atrocities committed with DBMSs, someone would have attached a generator to him, and we would have heard of this near-infinite source of electrical power.

Sincerely,

Gene Wirchenko


Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:22 • by OneFactor
57191 in reply to 57188

Anonymous:
If they replace true and false with #00ff00 and #ff0000 then I'll be impressed.

Of course when they come across #ffff00 then they're fucked!


Gives a whole new meaning to the word phrase #ffff00 barred.


As for the bit datatype in SQL Server, my favorite part is when I open up the table in design mode and find out that the column allows nulls.


Though why we are fussing about the red-green thing when the table is not even in first normal form boggles the mind. Table which are not in first normal form make baby Jesus cry. The worst that the red-green would do is make Santa Claus turn over in his grave [:P]

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:25 • by R.Flowers
57192 in reply to 57187

BlackTigerX:
I think I know the guy who wrote that...[+o(]


Assuming you're not just joking here, do you know what the application was for? Was it a 25 page web site stored in the DB, or...?

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:26 • by Joost_
57193 in reply to 57189
> Are you serious? A boolean is now a tri-value? Wow.

I think he means the field is only really a boolean if it's declared as NOT NULL.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:27 • by JohnO
57194 in reply to 57177

Anonymous:
I don't think SQL Server has boolean, but it does have a 'bit' data type, which can be 1/0 (of course). ASP (at least) interprets the bits as "True" or "False" in an ADO recordset.


Bit can be 1, 0 or null.  This may sound picky, but I have seen T-SQL such as this:


IF @bitParam = 0...


Which doesn't get invoked if @bitParam is null.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:32 • by merreborn
Alex Papadimoulis:

Relational databases don't have Boolean data types for good reason: the inherent nature of tri-value logic (i.e., true, false, and unknown/null) makes it a logical impossibility.



I'm going to assume the users who have claimed that this statement is in itself a WTF are either (1) familiar with the WTFs this is a sarcastic reference to, and are themselves being sarcastic or (2) new to TDWTF

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:36 • by rbriem
57196 in reply to 57188

Anonymous:
If they replace true and false with #00ff00 and #ff0000 then I'll be impressed.

Of course when they come across #ffff00 then they're fucked!


Actually, I think they'd just be yellow.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:41 • by enigmatic
Perhaps I should stick with "Yup"/"Nope"/"Meh"

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:43 • by Suck My Lisp
57198 in reply to 57176
Gene Wirchenko:
This statement is a WTF itself.


Yup.  In addition to your criticisms, all you need is a "not null"
constraint to knock the "tri-state logic" down to binary.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:49 • by OneFactor
57199 in reply to 57196
rbriem:

Anonymous:
If they replace true and false with #00ff00 and #ff0000 then I'll be impressed.

Of course when they come across #ffff00 then they're fucked!


Actually, I think they'd just be yellow.



So it would only be a problem for the original Green Lanterns?


In varest char, in one-bit byte 
No column shall escape my sight
Let those who worship first-normal's might
Beware my power, Green AppForm's light!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 15:59 • by WTF Batman
57200 in reply to 57176
Gene Wirchenko:
Alex Papadimoulis:
Relational databases don't have Boolean data types for good reason: the inherent nature of tri-value logic (i.e., true, false, and unknown/null) makes it a logical impossibility.


This statement is a WTF itself.  If you require tristate logic, then do not use binary logic.  This is much the same as selecting a fixed decimal type when representing currency instead of using integers.  Pick the appropriate type.

Some DBMSs do not have boolean.  Some do.

Sincerely,

Gene Wirchenko



And, of course, this "tri-state" nature of said "boolean" data type is easily obviated by simply adding "not null" to the column definition.

Booleans are easy to create. Add a check constraint to make sure the value is 0 or 1 (or T/F, or R/G, or...) and a "not null". How to do so on each RDBMS varies, but it's by no means impossible, or even difficult. (mysql users can use an enum column, instead of check, I believe.)

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:01 • by Alex Papadimoulis
57201 in reply to 57176

Gene Wirchenko:
Alex Papadimoulis:
Relational databases don't have Boolean data types for good reason: the inherent nature of tri-value logic (i.e., true, false, and unknown/null) makes it a logical impossibility.


This statement is a WTF itself ... Some DBMSs do not have boolean.  Some do.


All Relational Databases that I know of support NULL. When the concept of NULL is introduced, you have tri-value logic. The concept of tri-value is a bit foreign since the overwhelming majority of languages are Boolean-logic based.


With Boolean logic, "x || !x" (where x is a boolean expression, such as "y == z") is a tautology. In tri-value logic, it is TRUE or NULL. Even the expresion "m == m" is could be TRUE or NULL in tri-value.


This is why tri-value languages will have an IsUnknown or IsNull test, which is the only thing that can be used to compare such values.


Hopefully you now understand why it is therefore impossible to have a Boolean datatype (two values) within a tri-value system.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:01 • by Brian

The big WTF is that the programmer didn't consider the future problems this would cause if the next programmer was red-green colorblind.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:02 • by Alun Jones
57203 in reply to 57180

ferrengi:
2) Also, since these Is_Complete columns only have values of "green" or "red" (or maybe "null" since they have to put something in there because the column is defined as NOT NULL, which is also stupid. The content and title can be NULL but Is_Complete must have a value! WTF?!). Anyway, I digress, why does the column need to be varchar(15), what's wrong with varchar(5)?


The answer is obvious - if you've been around the computing field as long as I have, you'll have come across the issue of trying to translate an app to a foreign language.  The 15 character size is designed to take into account the possibility that the words for "red" and "green" in some foreign language might be very long indeed.


Or maybe it's to provide for future requirements - someone may want to include "chartreuse", or "azure", maybe even "Post Office Red" (15) or "British Racing Green" (oh, poopies).


[Oh, that's subtle - the failed captcha is "register"]

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:05 • by Otto
57204 in reply to 57199

Heh. I've seen the True/False/Null nature of a relational database mess people up sometimes, when they forgot to put a NOT NULL on the declaration or didn't know that they could.


Although the more usual workaround to this essentially turns that trinary into a binary by simply treating a intended boolean field only with "IS NULL" or "IS NOT NULL" in the statements regarding it. Then any value in the column becomes "true" and null in the column becomes "false". Or vice-versa.


 

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:07 • by Alex Papadimoulis
57205 in reply to 57200

WTF Batman:
Booleans are easy to create. Add a check constraint to make sure the value is 0 or 1 (or T/F, or R/G, or...) and a "not null". How to do so on each RDBMS varies, but it's by no means impossible, or even difficult. (mysql users can use an enum column, instead of check, I believe.)


From a logic perspective, this still does not make a Boolean type, merely a constrained domain.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:12 • by WTF Batman
57206 in reply to 57205
Alex Papadimoulis:

From a logic perspective, this still does not make a Boolean type, merely a constrained domain.



That's true, but from the application perspective, that's generally good enough. Most languages interpret 0 as false and 1 as true, so boolean-context comparisons on the ints work as expected.

You're right in that this is a kludge, but it's a good kludge in that it at least only allows logically true/false values and nothing else (red and green, for instance). Certainly helps from a data integrity perspective.

I remember a WTF a while ago about a TPS report where it was "reportable" with like 10 different varieties of "yes" or "no". This kludge would, at least, prevent insane cases like that.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:14 • by Clinton Pierce.

The programmer was obviously Canadian, and as we all know:


If the women don't find you handsome they should at least find you handy.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:15 • by John Bigboote
57210 in reply to 57201
Alex Papadimoulis:




All Relational Databases that I know of support NULL. When the concept of NULL is introduced, you have tri-value logic.





Sybase ASE does not support nullable BIT datatypes.



Go ahead, ask me how I know this.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:16 • by OgT
Anyone ever seen the Red Green Show on PBS?

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:22 • by OneFactor
57212 in reply to 57198

Suck My Lisp:
Gene Wirchenko:
This statement is a WTF itself.

Yup.  In addition to your criticisms, all you need is a "not null" constraint to knock the "tri-state logic" down to binary.


Young grasshopper, observe the stored procedure. Meditate on the beauty of its parameter declaration. See how the tiny bit datatype wishes to be free of the dualism imposed by two-valued western logic. For if the student knows NOTHING can be other than one or zero, the enlightened will learn know that nothing CAN be other than one or zero. Even as the brutish developer tries to coerce the parameter into but two values by providing a default of zero, the parameter yields like the slender reed to the howling storm and allows itself to be invoked with an explicit null.


Consider also the left-outer join as it frolicks in your view. Unlike the inner join which only gives after it has received, the left-outer join has transcended selfish greed and the demands for O(n) performance. It can cheerfully give of itself as an orphan who has nothing even without the material riches provided by parents. And in doing so, it too will transcend the duality which the not-null constraint imposes.


To understand the database you must unlearn the dualism you have learned in your computer science. And that, young grasshopper is why you need to place a W in front of the sacred letters of Boolean Algebra: TF.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:29 • by WTF Batman
57213 in reply to 57212
OneFactor:

Suck My Lisp:
Gene Wirchenko:
This statement is a WTF itself.

Yup.  In addition to your criticisms, all you need is a "not null" constraint to knock the "tri-state logic" down to binary.


Young grasshopper, observe the stored procedure. ...[snip]... And that, young grasshopper is why you need to place a W in front of the sacred letters of Boolean Algebra: TF.



Genius! Pure, unadulterated genius!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:32 • by Fregas

This is because its in VB.NET, instead of C#.


Let the flame wars begin!!!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:37 • by pbounaix
57215 in reply to 57212
**somewhere in the distance a gong is heard**

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:49 • by Gene Wirchenko
57216 in reply to 57212
OneFactor:
To understand the database you must unlearn the dualism you have learned in your computer science. And that, young grasshopper is why you need to place a W in front of the sacred letters of Boolean Algebra: TF.


Transcending and not transcending: the new duality.

Sincerely,

Gene Wirchenko

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:50 • by Shadow Wolf
57217 in reply to 57199
OneFactor:
rbriem:

Anonymous:
If they replace true and false with #00ff00 and #ff0000 then I'll be impressed.

Of course when they come across #ffff00 then they're fucked!


Actually, I think they'd just be yellow.



So it would only be a problem for the original Green Lanterns?


In varest char, in one-bit byte 
No column shall escape my sight
Let those who worship first-normal's might
Beware my power, Green AppForm's light!

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:53 • by emptyset
Alex Papadimoulis:
"green"/"red".


strings are more expressive than puny, weak bits.  this is what happens when you demote a comptroller.  never demote a comptroller.  revenge assumes many chloroforms.

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:55 • by nobody
57219 in reply to 57210
> Sybase ASE does not support nullable BIT datatypes.
> Go ahead, ask me how I know this.

how do you know this?

Re: The Green, the Whole Green, and Nothing But the Green

2006-01-19 16:59 • by Satanicpuppy
57221 in reply to 57183
Anonymous:
I use the bit datatype for booleans in SQL Server.


Meh. I use the smallest flavor of int, whatever it happens to be. Sounds a little wierd, but if you need to be able to represent null, you need more than 1 and 0. I prefer null = -1 myself, because -1 fits into a lot of languages built in error checking procedures.

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment