- 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
Easy enough.
SELECT * FROM some_user_table WHERE onlinestatus = @Online OR onlinestatus = @Offline
(forgive my weak variables-in-SQL-fu if there's anything wrong in that syntax.)
Admin
how about this forum software?
Admin
I like the way both variables are declared varchar(100)just in case you want them to be 'YYYYYYYYEEEEEEESSSSSSS' or something like that. Why send a bit when 100 bytes will work? Unfortunately, he didn't use nvarchar(100) so this is clearly not suitable for international applications.
Admin
For the first time in ages, I stared at the code and actually said "What the F!"
Admin
"Both" is obviously the authors implementation of the third boolean value...
Admin
Theory.
The application was written with separate variables for Online and Offline, because the author was stupid. Thousands of features were added which depend on having these two variables.
A smarter person said "these are the same variable" and created the OnlineOffline variable. For compatibility, he used it to set the original two variables, so he didn't have to fix the old code.
Along comes someone either stupid or brilliant (or more likely brillant), who says "there's actually a third mode which is both online AND offline" and creates the "Both" value.
And of course, a rarely-used function deep in the bowels of the system sets the OnlineOffline variable to "FileNotFound", which breaks everything.
Admin
It is a case of enmeshed double-backloop logic, in which the truth of the opposite does not necessarily imply the falsness of the other, nor does it negate the other way around if the same becomes truly false.
See? Simple!
It's that higher system Godel implied which can express the contradictory/recursive/closured logic found in our current system.
Admin
Welcome to the world of quantum computing, where a system can be online and offline at the same time. Until you measure it that is.
Admin
-True -False -FileNotFound
The CAPTCHA is "ewww" which is exactly my thoughts about this section of code.
Admin
I'm confused how someone can be online and offline at the smae time!
Admin
The WTF is actually:
He states 'Both':
Online = 'Y' // Thus it's online Offline = 'N' // Thus it's NOT offline
He states 'Y': Online = 'Y' // Thus it's online
He states 'Y': Offline = 'N' // Thus it's NOT offline
So.... It is ALWAYS online!!!! There is nothing to check, since the answer is always the same!!!! Simply saying:
Online = TRUE
Would be the only answer possible and saves a lot of lines.
Captcha: howdy (I'm fine thank you)
Admin
I'm confused about someone can be online and not be offline. Sounds like the Matrix to me.
Admin
Should be:
He states 'N': Offline = 'N' // Thus it's NOT offline
Sorry about that...
Captcha: ewww (I already said sorry, 'K??)
Admin
unfortunately, no one can be told what offline is.
I suggest the blue pill.
Admin
FOOLS!!! It's simple ternary logic. Using varchar as the data type to represent it is the real WTF.
Captcha: doom (you didn't need to tell me)
Admin
I think you got it.
Taking snippets out of context can cause them to not make any sense, but in context you understand the code easily.
Sure, in this particular case, it may not be a perfect solution, but it works quite well if you think about it.
Admin
It's obvious that this is for a high availability system that must always be online.
Admin
I dont know this code context...but..I hope those values arent being used later on (umm..then, what's the point to initialize them?) because the possible values of @Online and @Offline are: ('Y','N','').
So, it's a FileNotFound inside a FileNotFound.In fact, if @OnlineOffline='Both',at least it gets "consistent" values for @Online and @Offline...
Admin
As far as I can see the @Online variable will always have one of the two values null or 'Y' and @Offline variable will always have one of the two values null or 'N'. I am not sure what he does with the values.
Captcha: smile :)
Admin
Yes, I believe you are right, it's a godel thingy. Still .. if you are neither online, nor offline, and i accept that is follows that you have to be both, I still dont accept you are either ...
At least that's wat my tortoise named Achilles claimes
Admin
That is NOT a piece of SQL
Admin
So we're checking online/offline status of Schroedinger's cat?
captcha: sanitarium
Admin
That still begs the questions why you need to check for onlinestatus. You are either online or you aren't. That would make these two SQL statements identical in functionality:
SELECT * FROM some_user_table WHERE onlinestatus = @Online OR onlinestatus = @Offline //always returns all records
SELECT * FROM some_user_table //always returns all records
Admin
Ok, let me spell it out for you all.
Imagine this :
So when you call GetUsersByOnlineStatus with 'Y' you get online users, with 'N' you get offline users, and with 'Both' you get... both.
Admin
Oh! That's the WTF.
quake - ahh, those were the days.
Admin
Take MSN for example. You can be online (i.e. signed in), and appear offline at the same time. So, you would be both online and offline... Depending on your frame of reference ;)
CAPTCHA: relativity ftw
Admin
We should consider, that it could be online or not in about 6,6*10^240 Ways. So, about 256^100. And we also consider that it is the same with offline (or not).
I want to see anybody working out that much ways of beeing online or offline ;)
Admin
I think this SQL fragment is the equivalent of Abbot & Costello's "Who's on First" skit. Or maybe that scene from Airplane 2: "Unger, didn't you serve under Oveur in the Air Force?" "Not directly. Technically, Dunn was under Oveur and I was under Dunn." Et cetera.
Admin
That actually is kind off clever, in a really stupid way.
Admin
It looks like the @OnlineOffline field is used to indicate which of the other two fields, or both, is to be set.
The code is called when the status becomes online.
There should be a similar block of code when the status becomes offline.
captcha: Tesla. But give the credit to Edison since he had the business case right.
Admin
Is like Womens. Womens are online. Only not available to YOU.
Admin
Rather than crazy logic like that, why not just roll the checks into the sql query:
Admin
Well if you want to be picky...
And while we're at it, isOnline should be a BIT to begin with.
As I said in my first post, the solution is less than perfect, but it works pretty well. It is clearly not a WTF.
Admin
Admin
For the millionth time....I laughed my @$$ off.
Admin
It's really quite simple: as long as you accept that x) you have to be both online and offline, and y) (a AND b) IMPLIES a (similarly, (a AND b) IMPLIES b) then because ((p IMPLIES q) AND p) IMPLIES q z) you have to be online (similarly, you have to be offline)
Finally, I have a record for your tortise to listen to...
Admin
An intelligent person would just keep a list of places where it was online.
The real question is what the complete list of OnlineOffline states are. Both, None, Tuesday etc.
Admin
The reason I did it my way rather than your way is yours does not deal with @OnlineOffline and isOnline both being the same, invalid value. Both could be 'Space Shuttle' and it would be returned. Doing the @a = 'Y' and @b = 'Y' would be the same as @a = 'Y' and @a = @b, with one fewer variable references. I don't have the DB schema, so I don't know whether isOnline would be enum'd into only Y or N values, in which case yours would be the same effect. But for a non enum'd varchar(100), @OnlineOffLine = isOnline could return false positives.
Admin
But...
isOnline = null
is not valid SQL, is it?
Admin
Oh, I disagree. The code shouldn't have to be a failure in order to qualify as a WTF. A function or code snippet can be technically exactly functional, may even be a smart solution to a problem in its context, and yet generate that "WTF?" reaction upon reading. I think this is an excellent example: when I saw the post, I could not possibly imagine what the author had intended, and yet you and fennec came up with an entirely plausible explanation. Kudos to you both.
Admin
Hehe, man you guys have WAY too much time on your hands.
Actually it is not regarding users online, it is regarding the status of some piece of data.
Some pieces can be online, others offline. Some users want to see both of these.
The WTF is really that they used a stupid dropdown to provide a parameter for a reporting services stored procedure.
The naming is totally not logical.
Would you like coffe or tea? Yes please!
Admin
isOnline should be a BOOLEAN, but (as of SQL:2003) BOOLEAN is optional because people keep arguing about how NULL and/or UNKNOWN (sound familiar?) should be handled. PostgreSQL gets it right (I wish I could use PostgreSQL at work), everyone else has an ugly-but-good-enough equivalent (BIT is MS SQL's), which makes Joe Celko roll in his grave (despite the minor detail that he isn't actually dead).
Admin
Its a 'varchar', so the db will store up to 100 bytes, depending on what was in the field. Unlike a 'char' type, which would always store exactly 100 bytes, regardless of the field's value. So that in of itself isnt a big deal.
Admin
"Both" I thought I was witnessing a Qubit!
Admin
Out of context or not, here's the results of the three possible(?) values off OnlineOffline:
when OnlineOffline = 'Y'
when OnlineOffline = 'N'
I'm guessing there's some appendix code here somewhere. Offline is either 'N' or null, Online is either 'Y' or null. I haven't even touched on the fact that we don't see what may have happened to OnlineOffline prior to this snippet, and assuming it's also varchar(100), the value could be just about anything. Hm, what happens then?
WTF?
Admin
As I understand it, you can compare things with NULL - it's just that the result of such a comparison is always false. So
andshould both return 0 rows.
Admin
the real wtf is everybody discussing this poor code...
Another wtf is my CAPTCHA test right now... YUMMY!
Gloves, remember and keep for yourself: gloves! http://thedailywtf.com/Articles/The_Complicator's_Gloves.aspx
screenshot: http://img256.imageshack.us/img256/8049/yummy6pt.jpg
Admin
Mmm, nope. Wrong. You're thinking of @Online and @Offline as the actual state. They're not. They're variables, string variables (varchar) and the way they're set out, it works like this: @OnlineOffline = 'Y' => @Online = 'Y' => @Offline = null (I think) => SELECT * FROM some_user_table WHERE onlinestatus = 'Y' OR onlinestatus = null
@OnlineOffline = 'N' => @Online = null => @Offline = 'N' => SELECT * FROM some_user_table WHERE onlinestatus = null OR onlinestatus = 'N'
@OnlineOffline = 'Both' => @Online = 'Y' => @Offline = 'N' => SELECT * FROM some_user_table WHERE onlinestatus = 'Y' OR onlinestatus = 'N'
--- this one, and only this one, is equivalent to SELECT * FROM some_user_table
Admin
Obviously, the code is an attempt at world domination.
Admin
Nah, just Schroedinger's Mouse in this case.