- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- The State of the Arts
- Planing ahead
- 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
"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."
By this logic, most programming languages are tri-value, but that doesn't excuse the fact that a boolean is T/F (on or off). To say that NULL is a valid boolean value is to miss the point entirely.
What does this evaluate to?:
boolean myBool;
Does that make this a valid boolean from a systems perspective? That is why this triv-value stuff is bunk. There are always constraints you need to put on a system to make it work. In this simple case, you need to define myBool to some initial value to prevent nulling out. In the above case, a simple NOT NULL does the trick.
Admin
I'm thinkin' it was generated, all right. By morons!
Admin
Those of us who, you know, actually work with databases, and realize that a boolean column that is nullable does, in fact, have three distinct possible values.
Check it out: True, False,
FileNotFoundNull. Five values. What? Oh yeah, three.Admin
Today's WTF: FileNotFound was supposed to render in strikethru. It does in the editor, but already know that is it's own WTF. I bet it'd be better if it were in JavaScript.
Admin
<font size="2">You heard it here first, folks: red is the new false.
</font>
Admin
<font size="1" style="font-family: verdana;">
<font size="2">Not if #ffff00 means FileNotFound.
Or you could use this scheme to redefine the tri-state boolean: True, False, ASuffusionOfYellow.
</font></font>
Admin
That, of course, would be "false". ((#ffff00 = #00ff00 & #ff0000, and everyone knows true and false = false))
#000000 on the other hand, would be "true" ;)
Admin
Precisely to prevent that kind of confusions, that's the reason I always use quaternary boolean logic: true, false, null and undefined.
Admin
And so the circle closes. The naive solution of placing a not null constraint on the column does not solve the parameter or left-join issue. For if we treat 1 and 0 as truth because they are not null, and treat null as false, then we CAN restore duality to the database at all levels. And so, grasshopper, when and only when we transcend the difference between 1 and 0, do we then have the foundations for the two-valued dichotomies that the learned yearn for and the wise spurn.
Your mission, should you choose to accept it, is to introduce transcendent negation, conjunction, and equivalence operators which operate or the 0,1,null set which correspond with the traditional boolean operators operating on the T,F set. If you fail on this road to enlightenment, your master will officially deny any knowledge of this endeavor - for the Tao which can be spoken is not the true Tao.
Admin
Umm, no you don't. There is already a value to represent Null. It is (drum roll) - Null!
Admin
This is fantastic!
True: #00ff00
False: #ff0000
Null: #0000ff
Half-Truths: #008800
False Positive: #ffff00
Pessimistic false: #88ff00
Intangible false: #ff0088
Indecisive: #888800
Who cares: #888888
Purple: #C000C0
This multistate logic is brilliant.
And: Intangible False & Pessimistic False= #880000 (Barely false)
Or: Half-Truth | Purple = #C088C0 (Rather gay looking indetermiate truth)
Xor: False-Positive ^ Half Truth= #887700 (Kinda leaning towards false)
Not: !Intangible False = #00ff77 (Slightly less tangible true)
Its brilliant! I should patent it!
Admin
With SQL, this should be updated to "The Tao which can be spoken is not the NULL Tao."
Sincerely,
Gene Wirchenko
Admin
I hate you all. I'm color blind.
Admin
No no, they've got it all wrong! It's Red, Green, and ErrTrafficFault.
Admin
The so-called "third state" of boolean, the null - has significance in that it simply points out that no decision has been made on true or false. No challenge has been encountered that would provide clarity. It remains to be seen if the data proves one way or the other. It's waiting to be solved. By having an explicit true or false value, we also know that the data has been tested and resolves.
Based on implementation, a nullable boolean ( or similar type ) could reveal something valuable if you're looking for an unproven true or false.
Case in point: an incomplete survey. Lets say for whatever reason, the user failed to finish all the questions on a survey. When you run the metrics, you could safely ignore the null values rather than casting them to false, which might be the wrong assumption and bais the results.
Admin
And for financial applications where the invoces are in dispute, the isPaid column can contain the color.... #BADFEE
Admin
Bravo! You made my day.
Admin
How about always reading from a computed column with the expression ISNULL(<colname>, 0), where colname is a bit column. You will always read 1 or 0, even when the value is NULL and even for JOINS. There is still a memory load in that you have to actually remember to join to the computed column, but it is possible.
You could also go one step farther and create a View on the table using the expression above and INSTEAD OF triggers to make the view fully updatable. Use permissions to funnel acces to the view instead of the table. It's a lot of work and most likely not worth it, but it is possible.
Admin
I think you are all #C00C00.
Admin
ROFL!!! Shame on you! You made me wake my kid!
Admin
"Touche"
Admin
I'm seeing a lot of common workarounds for the absence of Booleans; but, putting aside the tri-state issue, all of these hacks are a pretty poor substitute:
myBool = not (myBool)
is meaningless with all the hacks we use day in and day out. The only exception I can think of was the old VB Boolean, where True = -1. It was another hack; but, the compiler itself made this syntax functional.
Admin
Programming Test;
Take one Green Crayola.
Take one Brown Crayola.
Mix the two together for the "Tri-State".
What do you get?
Brown.
No Shit. . . I mean, . . . . well, brown, you know, like sh*t.
You either get it, or, you don't. Or, maybe, you're just confused.
unreal won't work. (captcha). Maybe FREEDOM will. . .
Admin
<font style="font-family: verdana;" size="1"><font size="2">"Or you could use this scheme to redefine the tri-state boolean: True, False, ASuffusionOfYellow."
Oh come on, am I the only one who gets this? :(
</font></font>
Admin
Admin
Pterry Pratchett again?
Admin
Can we not have SQL WTFs anymore?
1) They're generally incomprehensible (as is SQL itself)
2) They're not interesting (because, let's face it, SQL is really just COBOL, and COBOL is friggin' dullsville, not to mention soooo last-century)
3) Okay, so maybe SQL is really more like RPG and COBOL had a baby, but the point remains
4) It's not really a WTF when someone does SQL badly, because it's not possible to do SQL well (along the lines of, "there's no such thing as playing the oboe well")
5) I've already done my hitch in the RDBMS Corps, I don't want to go back, and don't need reminding that I was there in the first place
Just a thought. And not much of one, at that.
Admin
Not wanting to be a stick in the mud or anything, but, IMO, if a value can be anything other than TRUE or FALSE (including NULL) then it's not a true boolean.
I realize it's rarely enforced, but the definition of boolean is: Of or relating to a data type or variable in a programming language that can have one of two values, true or false
The REAL WTF here is that ANY system allows you to have a boolean value that is neither TRUE nor FALSE (ie: null or yellow, etc.)
Case closed! ;)
Admin
Glenn? Is that you?
--
telnet towel.blinkenlights.nl 666
Admin
Admin
Love the site, been reading it for months and months. Gives me hope every morning that everything isn't quite as bad as it seems.
However, this WTF just had to be replied to. This is probably the worst .NET code I've seen in a long long time (and believe me I've seen some right corkers).
SQL Server HAS a boolean equivalent (bit field with NOT NULL as everyone has stated), ADO.NET correctly maps this to a boolean type in both Readers and DataColumn's so WTF were they thinking of?
My suggestion, apart from the ludicrous use of colours to depict yes/no is this could probably have been an ASP application that was ported (or was perhaps someone's first attempt at an ASP.NET application after coming straight out of the 'ASP' camp) without fully comprehending what they had available to them.
A common first mistake when starting ASP.NET apps is approaching it like an ASP application. Was at a client's last year and they had done the same (purely out of inexperience of the CLR and underlying framework) and the code was an utter mess. Totally unmaintainable and damn right scaringly bad.
Kept me busy for a good few months believe me getting things straight.
Admin
No, the untimely passed away Douglas Adams in his book 'The Long Dark Tea-time of the Soul".
All Douglas Adams books are recommended reading material for programmers, or even for people pretending to be programmers.
Christ
Admin
Where does it say "boolean is a 'tri-value'?
Admin
*snicker*
[insert elitist programmer comment here]
Admin
Man .. I know, I should've taken the blue pill ;)
Imagine a designer meeting with all new people trying to agree on the colors for the different values. No one wants to back down .. hey, that's Resevoir Dogs isn't it.
Admin
imho Adams is one of the most overrated writers (among nerds, that is) out there. yes, i've read more than one of his books. no, i did not think they were brilliant; i thought thay were boring and plotless.
have you ever read books by other authors?
Admin
OK, this really looks similar to something I did 6ish years ago. Except the Java has been replaced with .net . And it wasn't an application form but a status monitoring. But I can explain how something near identical happened...
There was a database table which had to be displayed on a web page. The guy doing the sql found out that it the column showing IsComplete was to be represented by images green.gif and red.gif so he thought he was doing me a favour by returning those strings. He worked too slowly for me even to consider asking him to change it to a regualr boolean so as soon as he had some Stored Procs I could use I just made do. Then later the picures were changed to checkboxes and the code ended up like the above.
Admin
The follow-up left a bit to desire, though. It is less coherent, the form is vacillating, and of less virtuouso a style.
If your world is impoverished enough that you truly cannot think outside a strict boolean logic, or that you consider anything not a sentence formally reducable to a two-state mutually exclusive mode fundamentally flawed, or that computers should not be able to handle anything beyond the nature of it's smallest informational component, then you should change career and apply for a position as resident mollusk on a seal somewhere.
The matrix of our minds are not binary, yet we can think in boolean terms. Ccomputers are binary on the lowest level, but why should that foundation make illegal the handling of anything different?
Unless you simply mean that "if it is called 'boolean' then it should be two-state", that I can buy into.
Admin
Sorry, but as a programmer who also happened to major in English, I can assure you that Adams' writing is indeed brilliant by any standards. If you don't like his work, then presumably either you have a different sense of humour, or you yourself are the one who has not read widely enough to be able to appreciate his writing. I'll give you the benefit of the doubt and assume the former.
Oh, and Dirk Gently >> HHGG. Alas for the lost Salmon of Doubt!
Admin
I think this would indeed come down to a matter of taste.
Admin
"That, of course, would be "false". ((#ffff00 = #00ff00 & #ff0000, and everyone knows true and false = false))
#000000 on the other hand, would be "true" ;)"
Is this a WTF?
#ffff00 = #00ff00 | #ff0000
Admin
Not if "|" is a "bit-wise or".
Admin
This statement is a WTF itself.
Indeed. If one accepted the argument against storing booleans, one could make a similar argument against storing integers - coz people expect an integer value rather than a null,
Admin
As a matter of fact, I did... I've read books by Dean Koontz, Stephen King, Dan Brown, and scores of other authors. Not all of it could be considered 'high literature', but still... I've read more than 'just' Adams. And, as was also noted above, this is probably a 'taste' thing.
I've also read them in Dutch, and I must assure you, the English originals are on the whole a lot better. Lots of jokes can be made to work, and some others were 'missed'...
Admin
I solve all isues with nullable boolean logic inside databases by:
(field = 'Y' or field is null)
And then use that small unit to replace the ineffectual:
field <> 'N'
I do not fully understand why null is not UNequal to a value such as 'N' or 'Y' or 'Cucumber', since it is obviously not equal to them.
If the field can hold:
N
Y
null
Then why does [WHERE field <> 'N'] only select those where [field = 'Y'] and ignores the nulls as though they were equal to 'N'?
Admin
class kk {
public static void main(String[] args) {
System.out.println(0xffff00 == (0x00ff00 & 0xff0000)); // prints false
System.out.println(0xffff00 == (0x00ff00 | 0xff0000)); // prints true
}
}
Admin
Shouldn't the third, indeterminate state really be "cat".
It was popularised by Erwin Schrödinger in his book "QuantumDb".
Admin
<Unless you simply mean that "if it is called 'boolean' then it should be two-state", that I can buy into.>
That's exactly what I mean. If you need more than two states than pick another data type.
Thanks
Admin
I looked at this code and understood why there is no normalization, if you produced this crap what are the odds that you ever heard of normalization. I'm certain that if their db guy saw it and normalized it the original programmer would be at a loss as how to combine the results to achieve the front end code. No doubt we would see code like:
<the language below is of no particular flavour>
sqlquery1 = "select isComplete from PageStatustable"
sqlquery2 = "select isComplete from PageStatustable"
....
sqlquery25 = "select isComplete from PageStatustable"
if result1 = "y" then
sqlquery1_1 = "select content_page, title_page from pageContents"
end if
...
if result25 = "y" then
sqlquery25_1 = " select content_page, title_page from pageContents"
end if
and so on and so on....
How crap like this ever gets into production is beyond me.
Oh, if anyone wants to use this idea, please don't say it came from me.
Admin
Depending on the language, this would evaluate to the default value (.NET, Java, etc), or a random value, based on whatever bits happened to be flipped in the memory space allocated for the variable (C, etc). The same holds true with ...
int myInt;
cout >> myInt;
... prints an possibly random, but still a valid integer value.
Think of Nullable datatypes as ones where the IsNull bit is stored in the symbol table and not represented as some combination of bits in the variables memory space. Very languages have Null represented this way and have to resort to ugly "hacks" to implement the logic: creating a IntClass with an internal integer and a getter/setter for IsNull and Value, boxing all value-types and having a separate object to represent null, and so on ...