- 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
kinda reminds me of oracle's "DUAL"... it IS there ;-)
Admin
Well... I can see that most of that code does indeed make some warped sense. At least if you assume that the system should create tables as needed, maybe as some kind of upgrade script. I've seen worse things, along with their marginal justifications.
But catching exceptions, showing an error box, and THEN CARRYING ON AS IF EVERYTHING HAD WORKED? That's not even marginally justifiable.
Admin
So TRWTF is that this function doesn't return FILE_NOT_FOUND?
Seriously, it is really amazing what kind of brillant crap people can come up with when they have no idea what they fuck they are doing.
Admin
I don't suppose anyone could summarize here what this chunk of VB+SQL code does?
Admin
The function looks if a table with the given name exists in the database. The result is first written into and the read from a helper table, which is created on demand. Obviously the developer did not know an easier way to get back the result of an "exists" test.
Admin
I don't mind the on-the-fly table creation. In that case you're basically faced with create the table or fail the whole task. If the table is not there what else could you do? There's also a certain amount of benefit to putting the table creation code with the code that accesses it--gather like stuff together.
If creating the table isn't the right answer it almost certainly means the database needs to be restored from a backup and at that point it doesn't really matter what you do.
The error handling, though, is utterly unjustifiable.
Admin
Admin
To do this:
It checks to see if a table called "tblIsThere" exists. I'm saddened he didn't try to do this using recursion. If the table doesn't exist, he's making a sql string to create the table, with a single field, a BIT, named "isthere".
He executes the Sql inside a try/catch. If it fails, he alerts that it failed .. and then continues like nothing happened.
Then he updates the table, setting the value of isthere to 0. Again, inside a try/catch. Again, alerts if an exception is thrown and then continues like nothing is wrong.
He then checks to see if the table exists, and if it does he's updating tblIsThere so that the isthere BIT is switched to 1. Again, same try/catch "trick".
He then reads back the value of tblIsThere and returns the value of isthere, implicitly casting it as a booean
Admin
First it runs a query to see if the table tblIsThere exists; if it doesn't, it creates it.
Then it sets the value of the first record of tblIsThere to 0.
Then, it chekcs to see if the TableName string passed to the function exists as a table; if it does, it sets the first record's value of tblIsThere to 1.
The function returns true/false depending on if TableName exists in the database.
Admin
Part of the implied WTF (which some have missed, or perhaps pretended to miss for the lulz) is that this is the only function that does anything with this table. There are some things that it could make sense for a program to test (whether it can reach the database server at all, whether it can create/insert/update tables) but this function and table would still be a WTF regardless.
Admin
It makes my eyes bleed.
Admin
Too bad that this summary only appears here, instead of appearing as a comment at the beginning of the function.
Admin
tblIsThere? That depends on what the definition of the word "Is" is.
Admin
It's amazing what words some people will come up with when trying to communicate with educated people.
Admin
No, it never makes sense. Production code shouldn't execute DDL statements, with the rare exception of CREATE TEMP TABLE.
One can test a program's database access and DML statement permissions by following them with a terminal SELECT. I don't think most live applications should have DDL permissions.
Admin
Reminds me of that old trick to fool fellow developers:
Worked at least in Oracle 8 (might have gotten the CREATE TABLE wrong, but you get the point). Since then I always use "FROM SYS.DUAL" to be sure.
Admin
Admin
Of the lovecraftian kind of course, nothing like having fishy tentacled old ones to visit ones co-workers at night.
Admin
SELECT * FROM commentIsThere If Count = 0 Then INSERT INTO commentIsThere (isthere) VALUES ('BRILLANT') Else UPDATE commentIsThere SET isthere = 'FILE_NOT_FOUND' End If
Admin
This is perfectly acceptable in an Agile project. It's obviously "version 1" of this table. In the next sprint they will be enhancing it with more functionality, such as "DatabaseIsThere", "ServerIsThere", "NetworkIsThere", "UniverseIsThere", etc. ;-)
Admin
Admin
Nobody said that a boolean would be returned for UniverseIsThere. Clearly, it would have to be a string: "Maybe"
Admin
Obviously, UniverseIsThere must be able to hold the values 0, 1, or FILE_NOT_FOUND.
Admin
Admin
The "developer" who wrote this code sure as hell isn't the type of developer to make use of unit testing (or, judging from the cls prefix, know anything about writing code from the last 10 years or so).
The saddest part and for me TRWTF is that developers like this "developer" seem to be much more common than developers who do know what they are doing.
Admin
Admin
The only WTF in my mind is the isTableThere field. I hate it when people use tables to store info about tables. What's that called? Meta database? Database within a database? Something like that.
CAPTCHA: ullamcorper
Admin
Admin
Admin
The first half is typical VB drudgery to create objects and stuff to declare what you're obviously doing.
Then they create the table if it doesn't exist, make sure that there really is a row in this table. And do some other stuff, and set the row to 0.
Then they check whether some table exists, update isThere to 1 if it does, and request the value of the table.
I guess it never occurred to the author to simply:
SELECT COUNT(*) FROM INFORMATION_SCHEMA.blahblah WHERE table_name = ?
Because the I_S views are magical or something, so you can't just query them?
Admin
Everyone ain't profesional DBA knowing how to masage querys.
Admin
Admin
Indian ain't have shortened life span providing he stay away from massage in diarrhea food poisioning.
Admin
Production code shouldn't execute DDL statements
I couldn't agree more. Yet, I know of a certain individual who, when asked what would be the best way to implement a relationship such as "user->list of friends" (typical of a social network), recommended creating a separate table for each user. That means, each user would have his/her own list of friends in his/her own personal, private table created on the fly. It would be interesting to see if the DB behind Facebook contains indeed over 900 million tables...
Admin
I asked what should happen when the user updates info on an item. Should the update go back into his own table or back to the master table? Yeah, he admitted, that could get complicated.
So... ?
Nothing.
He could see a problem with his design, but could not back away from it or come up with any other solution. So he just stood there, silent, stuck at a mental dead end, without even the common sense to throw it in reverse.
I guess this is the expected level of brainpower for a former Director of Big Things (recently demoted).
Admin
One great thing (of many) about Agile is that it ushered in the code-first ORM era of development. That would surely have avoided such a ridiculous DB table.
Admin
Admin
The definition of "Is" is is is is is is.
Admin
Oracle has a built-in system table named "dual" with exactly one row. (Unlike some DBMSes, Oracle emits a syntax error on any query or subquery that doesn't have a FROM clause, so a single-row table is useful for things like "SELECT current_date FROM dual" and "SELECT 1 FROM dual WHERE EXISTS (...)" and so on.) Anonymous' code would hide that table by creating a non-system table with that name . . . and it would put two records in that user table, thereby causing lots of queries to return the wrong number of rows.
Admin
Admin
(Or perhaps the xkcd number; see http://xkcd.com/207/ )
Admin
Given how badly the web interface is designed, I would not be surprised.
Admin
Admin
It looks a bit like a broken semaphore: I.e., update to 1 to indicate that a process is running that can't be interrupted. Of course, nothing else checks the semaphore, including this routine, so all it really is, is one majorly incredible WTF.
Admin
How about a nullable boolean then?
Admin
Admin
I was of the opinion that this particular scarecrow should be secured, delineated and segmented.
Admin
Such is the professional practice of 'sharding' a database. It is best to put every user in her own virtual machine, so resource sharing is fair and can be managed by a hypervisor. I think friendship connections between users are represented by TCP sockets, so that messages can be exchanged easily. You see, this requires no traditional database at all!
Admin
Except shops such as the one that allows such a ridiculous DB table won't embrace Agile since ORMs mean you can't put everything in a stored procedure (and it means you gasp! have to recompile when the database changes!), and doing TDD means less time to sling code, and pair programming means you have half as many things going at the same time (because each task requires 2 programmers instead of one), and you can't bother the business users for requirements because they have "real" work to do...
Admin
HEAR ME EVERYONE. I AM IGNORING FAKE NAGESH, I REPEAT, I AM IGNORING FAKE NAGESH. PAY NO ATTENTION TO HIM, JUST LIKE I AM DOING NOW.