- 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 a trap!
Admin
Obviously, TRWTF is that it isn't forward thinking enough to consider the possibility of 60 results.
Admin
I DEFY ANYONE TO DEFEND THIS CODE!
Admin
At a guess, and do tell me if I'm wrong, you could, maybe, shorten it by removing the { and } after each case statement? It's a shot in the dark I know but it might just cut the code size down a bit.
Admin
<sarcasm>Don't blame the code!!! Blame the programmer!!!</sarcasm>
I don't wonder so much how programmers who write code like this get jobs... what amazes me is that so many of them have College degrees... therefore I would ACTUALLY blame the professors who passed them in the first place.
Admin
I suddenly have the urge to go diarrhea in my pants.
Admin
No, wait, I've got it - all those "Text.." labels have the same code! So, all we need to do is to put the common code into a default section and then add in empty case statements for all the other control names, a bit like:
case "Text51": break; case "Text52": break; case "Label1": break; case "Label2": break;
and so on. Note how I'm also not putting in those redundant curly braces to cut down the size even more!
Skizz
Admin
Admin
Hmm, a challenge... Maybe it was auto-generated? I would expect a machine to do things like this: mechanical, straightforward, lacking inspiration, and with a pig-headed refusal to ever change its way because in the end it is just a dumb program and not a human being who might see the error of his ways...
In some ways I find that comforting: the notion that my navigation system will never get angry with me for not doing what it says, but instead just tirelessly recomputes newer, better routes... Same as with this program. The predictability has a zen-like quality that induces a trance-like state where the mind is completely free from the shackles of everyday reality, allowing us to soar above the code and wonder at its shape and beauty.
I would also like to point out the considerable entertainment value the code is providing, although I will admit if you don't think of that as a valid point in the context of professionally-written computer software ;-)
Admin
I'm not a dev and without really looking the only word that kept screaming in my head was "regex", quickly followed by the phrase "dev team restructuring"!
Admin
Admin
It's a trap of course, anyway I try it: the "n+1" pattern?
(what is a pattern?)
Admin
I don’t see what’s wrong with that code.
Admin
THE GOGGLES DO NOTHING
Admin
I love the fact that the spaces are the same in each block, so the programmer most likely copy-pasted the same code over and over again.
Admin
wow ... just ... wow ...
Admin
what you wouldn't do for a default block. Then again maybe he just wanted to check if anyone read the code, a test !
Admin
Admin
Admin
When you think nobody could improve on the for-switch pattern, someone actually comes up with this. Excellent.
Captcha: genitus, the genious of the devs genitals?
Admin
TRWTF is that we just elected a socialist as the next President... Sorry, off topic...
Admin
paid per line.
Admin
I was on piece work :)
In the days of COBOL this sort of thing was not unknown when programmer productivity was measured in KLOC.
Admin
I know, I know!!! It needs xml and xslt!!!
Admin
var f =0;
There you go. He declared that variable and never used it. That will cut down at least one line......
Admin
Admin
Anyone who has ever used Documentum will be familiar with using XSLT and XML content to automatically generate HTML, ASP, ASP.Net, Javascript, you name it...(adding client-side validation based on the contents on the XML source for example would result in hideous code repetition, but not necessarily code that you'd have to maintain manually)... </DefendingTehCodez>
...but it's more likely to simply be written by one.
Admin
Admin
The for-switch pattern (or a variation) is actually used in commercial obfuscation products. If you disassemble, say, Apple's FairPlay, you get something like this:
Of course, the steps aren't actually in order. Often they implement loops using only math, excluding any ifs or other jumps - they just mathematically relate the result of the comparison to the next step value. It's like flattening each line of code to be inside a switch case, and then adding complicated code to transition from one step to another of the state machine.
Admin
OOH I know it! He can cut a few lines by using K & R or BSD KNF indentation styles.
Addendum (2008-11-05 08:53): And I would like to add to my fellow-countrymen' fun: "É uma cilada, Bino!"
Admin
But it's NOT consistent:
(Spaces round the '=' on the second line, but not the first)
Admin
I see the pattern.. each line has characters !
Admin
Hmmm. A pattern... What could it be? It's like trying to find an elephant in a hay stack!
Admin
Well, he could've made a function MoveNext() { window.event.returnValue=false; window.event.cancel = true; document.forms[0].elements[n+1].focus(); }
And call that from his switch. That's what I would've done anyway.
In case my boss reads this, just kidding...
Admin
LEAVE THE CODE ALONE! ;_;
Admin
Oh, that's easy. Switch statements use up extra cycles because of all those extra condition checkers. He should use a single IF statement, since each one is going to focus on n+1 anyways. This way you can get all those switch statements done with just one line. Sure, it'll be a long line, and you'll need to horizontal scroll to read it-- but the horizontal scroll bar only uses pre-compile cycles.
Admin
how about this?
switch (elementItem) { case "header1:SearchBox" : { __doPostBack('header1:goSearch',''); break; } case "Text1": case "Text2": case "Text3": case "Text4": case "Text5": case "Text6": case "Text7": case "Text8": case "Text9": case "Text10": case "Text11": case "Text12": case "Text13": case "Text14": case "Text15": case "Text16": case "Text17": case "Text18": case "Text19": case "Text20":
case "Text21":
case "Text22":
case "Text23":
case "Text24":
case "Text25": case "Text26": case "Text27": case "Text28": case "Text29": case "Text30": case "Text31": case "Text32": case "Text33": case "Text34": case "Text35": case "Text36": case "Text37": case "Text38": case "Text39": case "Text40": case "Text41": case "Text42": case "Text43": case "Text44": case "Text45": case "Text46": case "Text47": case "Text48": case "Text49": case "Text50": { window.event.returnValue=false; window.event.cancel = true; document.forms[0].elements[n+1].focus(); break; } }
I just can't see anything else that would make it smaller, expandable and easier to manage...
Admin
Since every case has three statements to execute, he could make it to always fall through two cases:
Admin
The real WTF is that the difference between Summary and Full Article on the front page is the final line.
Admin
I thought the exact same thing.
Admin
Would you marry me?
Admin
When I saw that the first thing you thought of here was the overkill of a regex, my first thought was "Thank God Fuzzypig isn't a dev!".
Admin
If this code were truly evil one of the cases, say about 2/3 of the way down, would be just a tiny bit different. with no explanation.
Admin
...don't exaggerate.
Admin
Good to see the for-case paradigm back :)
Admin
Well it works. What's the problem?
Time? Well assuming this code supports hours of runtime behavior and the copy pasting took 20 minutes, that's a fair tradeoff.
And what's the worse that can happen in the future?
Well if they need another 100 text fields, well okay that's a lot of copy-paste, perhaps 15 minutes work though. Not a big deal, especially if such a request is very unlikely to happen.
What if they need to edit the implementation for all of the text boxes? It might take 5 minutes to do that with search and replace. Again not a big deal.
You could define how bad a piece of code is as proportional to the likihood of it of wasting a lot of your time in the future. I don't find this piece of code to be bad under that definition.
Admin
Admin
if (elementItem == "header1:SearchBox") { __doPostBack('header1:goSearch',''); } elseif (("" + elementItem).match(/^Test\d+$/)) { window.event.returnValue=false; window.event.cancel = true; document.forms[0].elements[n+1].focus(); }
Admin
Better read up on your switch statements again there sonny.
Admin