- 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
It's from Microsoft Dynamics Solomon or as it is now called SL. They like to put things in alphabetical order. If this guy is a MS developer then it explains why SL sucks. If he develops 3rd party modules for SL then it explains why most of those suck.
Admin
I am not completely sure because it has been a while since I have last seen this code, but obviously he and Mr. Join were not best friends. Also was also not very familiar Mr. N. Form I-III and had something against relationships...
Admin
When the lion is after the monkey, being rapidly-conceived is certainly a requirement for the best solution, being the process of coming up with it part of the solution itself. A solution with a long conceiving process is therefore sub-optimal. But among the solutions that help the monkey be safe, there's probably one that makes the monkey run less, one that ends with a dead lion (assuming that's good), or one where the monkey gets hurt for trying to climb a tree without watching it puts its hands.
A perfect solution gracefully balances the time taken by the previous planning with the actual execution. Give enough space to the problem and this could be a suboptimal solution to the problem of finding a job, with the guy getting into CS in the first place...
sorry, just making such fuss about it b/c your reply was overly simplistic and didn't seem to really understand the meaning of 'optimal', but it also serves as a good argument pro-cowboy coding which most people here have to suffer...
Admin
"Optimum solution" and "well-fed lion" are mutually exclusive, you berk.
Admin
This seems to be written in either C# or Java; C# is more likely. It doesn't matter which, though: both of those languages use immutable strings, so every string concatenation is creating a new string and trashing an old one.
I count 327 string concatenations (with the help of a search in my code editor of choice), and that completely ignores the costs of Trim(), Replace(), and other objects' ToString() calls that could be potentially inefficient as well (given what this code looks like).
This single statement probably calls the garbage collector on its own. Twice.
Admin
I also had a reply for mr. Berk, but I forgot to quote him correctly.
When the lion is after the monkey, being rapidly-conceived is certainly a requirement for the best solution, being the process of coming up with it part of the solution itself. A solution with a long conceiving process is therefore sub-optimal. But among the solutions that help the monkey be safe, there's probably one that makes the monkey run less, one that ends with a dead lion (assuming that's good), or one where the monkey gets hurt for trying to climb a tree without watching it puts its hands.
A perfect solution gracefully balances the time taken by the previous planning with the actual execution. Give enough space to the problem and this could be a suboptimal solution to the problem of finding a job, with the guy getting into CS in the first place...
sorry, just making such fuss about it b/c your reply was overly simplistic and didn't seem to really understand the meaning of 'optimal', but it also serves as a good argument pro-cowboy coding which most people here have to endure...
Admin
Just about the only thing that ever changes on published vs submitted code are whitespace (as was this one) and occasionally domain names (like, "FarmerOwners" to "Customers").
The fomer is almost always stylistic (tabs vs spaces, etc)... but if it's goofy to begin with (no indentation, backwards indentation, etc), then I'll keep it in. So, like, today's, just picture all the linebreaks removed.
As for the latter... well, making that avaiable would somewhat defeat the purpose of anonymizing it in the first place.
Admin
Huh... that would mean you couldn't insert more than 32k of data into a row using normal insert ? That can't be right.
Admin
I believe the "escaping quotation marks by doubling the quotation mark" stems from the fact that SQL borrows rather heavily from COBOL (the language of choice at the time SQL was originally introduced).
32k ... bff - you wish. In Oracle, the longest text field is 4000 bytes. Of course, like any database I know of that is alive today, there are the "Large Object"-fields, that can store heck of a lot more data.
Admin
captcha: uxor. So suxor? Makes sense.
Admin
MY SENIOR ARCHITECT ASKED ME TO KEEP THINGS SIMPLE, SO I ADDED SOME SIMPLE, SIMPLE STRINGS AND THEN THIS HAPPENED. LONG LIVE LINES BREAKS FOR CLARITY.
Admin
Seriously,
What's really stupid, is assigning a measure of intelligence to a non intelligent object. Of course computers will run this code, they don't have a choice.
Admin
Ah, one of those bigots who think that all programmers are sloppy :)
Just because you avoid the APIs doesn't mean you leave everything unsorted. In fact, if his aim is to "keep things simple", then I can see imposing a logical ordering for maintainability.
Admin
I believe I've read somewhere that Java is optimized to use StringBuilder or some such class behind the scenes when dealing with multiple concatenation operators in a single statement. Can't speak for .NET but I'm sure it has a similar optimization.
Admin
Sorry, forgot to quote, my comment was in response to Windrider's comment about 327 concatenations of immutable strings.
Admin
Yes the proper way to do it is use a StringBuilder.
I remember a long time ago this was the only way to make a SQL call. This kind of thing was rampant back then, and nearly everyone wrote libraries to handle situations like this. Even if you used a stored procedure, the long list of parameters still exists, and you are still going to write some kind of statement for each one. A parameterized query object would actually make this code longer, but it would make it safer and a little more readable. While this code is funny to look at these days, it's not particularly surprising, and not really much of a WTF if you remember the old days.
Admin
Admin
Funny thing is that on my project, someone started using a StringBuilder to combine strings.
For instance instead of
they would use
Most of the entire code base is like this, but it is a lot easier to identify the parameters this way when you've got 10+ of them.
Admin
Admin
Task: Escape the lion. Optimum solution: A solution resulting in a well-fed lion?
SenTree is the real WTF here...
Admin
Admin
Except, that SQL Server (MS, anyway) often expands IN comparisons into normal boolean expressions when used with literals. Just botch the syntax and watch the error show up as many times as you have literals. You get a similar result with BETWEEN. I wonder if the limit is before or after the internal rewrite.
Admin
The other point worth making is that monkeys don't practice piano in order to escape lions. Neither do programmers (to escape lions or draw a salary). However, there have been many parallels observed between musicianship and programming ability. The difference is that you can earn money being a crap programmer, while you have to be a world class musician before you can even think about giving up your day job.
The optimal solution, therefore, is to study piano instead of trying to get the best grades in CS classes.
Damn.
Admin
Admin
The advisor replied in a snooty (read "snotty") manner that he should consider a class in anger management. Meanwhile, he should continue playing mandolin, and put some Hayden in the CD player during heavy traffic.
I wrote in reply that the dumbass should put the mandolin down and concentrate on his driving. "And forget Hayden," I said. Instead he should put in Pantera's "Vulgar Display of Power". He would identify so completely with the lyrics and the rage omnipresent in the music that his anger would be dispelled simply by being expressed in such a forceful manner.
Needless to say, it didn't get printed. :) </offtopic>
Admin
CATCHPA -- damnum. Probably what should happen to the example code section.
Admin
Eh, I've seen worse, and not just on here, either.
Admin
It certainly is. It's SOShipLine if I'm not mistaken.
This also explains why everything is in alphabetical order. SL has, since its infancy if I'm not mistaken, always had all its columns in alphabetical order. No column can be Null. AND the primary key of the table HAS to be TableName0. So in this case, the primary key is a unique clusetered index named SOShipLine0.
I hate myself for knowing this.
Admin
I have a friend to tends to do stuff like this. He writes up a SQL script that walks through the table (or view) and generates code on the fly.
For a tiny snippet (for SQL Server) that doesn't check datatype or anything like that:
Admin
Actually the doubling up of quotes is more an old mainframe sort of thing. And that's what Cobol uses, too. Since that's the environment that SQL came from, it's not unexpected that they used that technique.
Admin
Admin
Yes ladies and gentlemen our system is so robust it can handle 3 - yes 3 transactions per second!
Admin
Personally I think they should offer a performance enhancement to System.String to store an 'IsTrimmed' boolean and thus prevent a million billion iterations over the same string for the same information, namely, that there are no whitespace on the ends.
Better yet, create an entirely new string class called the TrimmedString, guaranteed to never have trailing or leading whitespace.
Admin
I was visiting the site from a new location, so I didn't have the "Show Full Article" cookie. I clicked to see the whole thing, got ONE glimpse at that monster, and changed my mind...
Hopping hacksaws, Batman! What is that thing?!
Admin
TRWTF is that he's not using a StringBuilder...
Admin
Admin
If you'd just left it as the one-liner it would have gotten printed. (And possibly syndicated.)
Elegant and optimal.
Admin
Assuming you must have a table with 109 columns, getting the data from SQL should be simple enough as you can get columns by index in many APIs.
Locally if you have some kind of variant type then you can loop through your columns and can always have enums when addressing column names individually.
Admin
Further to my last comment though, if the code being shown in this example was somehow "automatically generated" then it isn't such a big WTF after all, and it may well be they have a device to generate such code.
Auto code generation systems used to be popular around 10 years ago and can be better than templates / generics at times when those become excessively complicated.
Admin
Admin
Mr. IN came in to work around this problem temporarily, knowing that he would have to go quite soon and be replaced by something more bizar^Wefficient.
Admin
I took one from an MSDN page and modified it a few times. However I'd like to know - why arent't these GUIDs? (besides the facts that they are not globally unique and were stored in varchar(32) columns ;-))
Admin
Oh no they are not - A. Lion.
Admin
Admin
Until someone adds a column in the middle of the table...
Admin
Actually, there are usually many equally "optimum" solutions to a given problem. For example, all great semi-circles are the shortest paths from one point to the antipodal point on a sphere.
Even more actually: My intuition tells me the shortest path between two points in a plane is a straight line. Following Changs reasoning, it should be a 1 in infinity chance of guessing that. That's so unlikely I must be some kinda genius dude.
Admin
I fear I am following in your footsteps. Shoot me now.
Admin
Nope. In contemporaneous Postgresql you can escape single quotes almost with anything else: #SELECT * FROM table WHERE col ~* $$'something''that''need''quotes''insides'$$; Here the $$ is the quoting delimiter. Also it's the now preferred way to quote psql and plpsql functions: CREATE FUNCTION fun (INTEGER) RETURNS text AS $$ DECLARE argum = $1; retval = VARCHAR; BEGIN SELECT INTO retval something FROM somewhere WHERE somevalue > argum; RETURN retval; END; $$ LANGUAGE plpgsql;
In a side note, this article shows code that's not SQL, but's an OO sql interface or something.
Admin
"But in Computerland, there was no such thing as a 'best' solution. Once the complexity level of "Hello World" had been transcended, all that remained were overarchitecturized, hypergeneric, self-configuring, reflection-based enterprisoid ivory towers and fasthacked, copypasted, 9-3-1 monolithic 100000 line swamps barren of any but the autogenerated comments, with wide expanses of abandoned code in between, only crossed by the rivers of developers' tears. The only audible sound was the malevolent cry of a lone pencil and paper workflow circling overhead..."
Persto? Do I put that on my pasta before I write it to the database?
Admin
But simple means easy to write, right?