- 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
Its just there to slow down the browser.... don't want it to go TOO fast.
Admin
Any brave "code defenders" want to take a stab at this?
...I got nothing.
Admin
They just wanted to prove that they COULD count to 15 ....
Admin
I actually think this is why it was created... some misguided attempt to put a slight pause before the Click event is triggered.
Weird
Admin
Isn't it obvious? It initializes the header.
Admin
Someone who didn't quite understand Duff's Device?
Admin
Obviously someone gets paid by the line.
Admin
THIRD!
The coder was just kidding. Brillant!
The coder should have used IsTrue() or a ternary operator.
The name of the button is a nice touch:
Admin
Classic obsessive compulsive syndrome. You know those people that have to lock the door 3 times before it's properly locked? Same thing...intCount has to be not zero 15 times in a row.
Admin
This is obviously for performance--they are simply unrolling the loop. Way faster than this:
<FONT face="Courier New"><FONT size=2><FONT color=#000099>function</FONT> headerInit()
{
for (intCount = 0; intCount <= 15; intCount++)
;</FONT></FONT>
<FONT size=+0><FONT size=2><FONT face="Courier New"> <FONT color=#000099>if</FONT> (intCount != 0)
{
document.getElementById(<FONT color=#990000>'btnChkRslts'</FONT>).click();
}
}</FONT></FONT></FONT>
Although not quite as fast as:
<FONT face="Courier New"><FONT size=2><FONT color=#000099>function</FONT> headerInit()
{
</FONT></FONT><FONT size=+0><FONT size=2><FONT face="Courier New">document.getElementById(<FONT color=#990000>'btnChkRslts'</FONT>).click();
}</FONT></FONT></FONT>
Admin
They must be stupid!
They should know that this is the way to go:
Admin
I'd be almost certain that this works around a problem in a deranged browser that doesn't have the whole document loaded before calling the onload handler.
Admin
Arty, I was thinking the same thing. But that makes it even funnier. They should have just used the for loop and cut out the if statement, were that the situation.
Admin
I don't see a WTF here.
He's just making *extra* sure that the variable is initialized before it is accessed.
Admin
Actually I think I have a semi-plausible explanation for this. It's not handwritten code; it was generated by a JSP or some other preprocessing layer that generates the page we're seeing. The loop is not a JavaScript loop, it's a JSP loop and hence the loop code is invisible at this stage. The 'if' check at the end makes sense because the JSP loop could have run zero (or possily one) times resulting in this generated JavaScript code:
We have no way to know what the JSP loop was supposed to do because we can't see the code, but perhaps it was running through a list of items that correspond to checkboxes and adding something to the header for each item whose checkbox would be checked. The input data in this case didn't have any items which would result in a checked checkbox.
Admin
I think this code could only have been written by nazis without CS degrees.
Admin
I bet you just hit the nail on the head. He's got server-side processing generating a bit of JavaScript (I've done this myself), and instead of doing a server-side check to see if the loop ran more than zero times, he just outputs the loop counter every time and lets the JavaScript check.
Lazy, but understandable. Huh.
captcha: 'dinky'
Admin
This makes sense. Were there, by any chance, 15 of something? (rows, columns, emoticons, etc)
Admin
Mine goes to 11.
Admin
On a serious note, I know exactly what's going on here.
This is a PHP or ASP file, and the server side is doing some kind of validation. For every step, it increments a numerical variable and spits it out into Javascript. That way, when it gets to the end of whatever it's processing, as long as one of the situations was met and intCount was incremented, it should perform the click event.
Like if someone was filling in some user info, and you wanted to make sure they filled in at least one field. If "First Name" is filled in, increment by one. If "Last Name" is filled in...and so on. As long as one has a value, activate the click() event on that button.
Granted this is an utterly retarded way of handling the situation...
Admin
It could be that some compilers/interpreters may think he wanted intCount to be zero. By setting the variable to a non-zero number 15 times in a row, it knows he's serious, that he knows what he's doing, and leaves it alone. I've seen it a million times.
Admin
Good job Jesse. I got it a few minutes too late. And now for your prize: the trampoline chicks from The Man Show are here with vats of butter and a half-dozen lemmings. You control the action, my friend.
Admin
Best thread ever.
Admin
how literal was Alex when he said "Html document"? I would tend to agree with the ASP theory.......but if it's an index.html then obviously there's no asp involved. Unless something magical happens that I don't know about.
Admin
Guys, i am really disapointed that you do not understand the brilance of this developer.
We all know that you never know the OS on which the client side javascript code will run. What kind of systems people run these days... heard something about a burning fox recently.... [;)]
Now lets say you got a system that use a int definition that has a maxvalue of 14 then it is very likely that the number 15 will be interpreted as minvalue. This could evenwell be a unsinged int resulting in value 0. You would really not want to go checking results with button actions on those systems... would you? counting to 15 for this variable is only to generate javascript errors on those systems that do not allow integers to be greater then 0.
Admin
isTrue(headerInit()) ? 42 : fileNotFound;
Admin
Looks like it might have been some code that leaked out of a code generator.
Admin
Its obvious, of course, that this is done for thread safety.
Admin
...or possibly nazis above the age of 30 with a purdue CS degree?
I vote for the "this is server-side generated code that for some reason should ensure that the button is not clicked if no assigment statements have been output. Doesn't take are the WTFery, just a very pausible explanation...
Admin
blink blink
I have trouble believeing that a computer would generate this. On some level this defies all known logic ....
Admin
Sincerely,
Adolph Eichmann
I invented Gene Nixon.
Admin
Admin
Maybe the html is generated, and some code is missing...
Admin
I agree. This dude has got skills.
Admin
Speaking of wtf, the site's editor couldn't escape a less than sign (it just removed the JSP tags sorry about the worthless example)... .
Admin
The real WTF is that they should have used JavaScript.
Oh.
Admin
Getting paid by number of lines!! I wouldn't be surprised if they had done the same for intCount = 1000.
Admin
Correction: m4D 5k1llz
Admin
Admin
i'm thinking maybe it's similar to those stupid CSS "hacks" that are floating around. most browsers would go ahead and "click" the button, but maybe there's a certain browser with a flaw in it's javascript implementation and he was exploiting that flaw to get a specific effect on a specific browser.
Admin
I take it you've never heard of setting MIME-types or handlers? index.html could contain PHP code, ASP code, Perl, whatever....
Admin
Huh ????? Nope - you have me here ....
Admin
Maybe the guy was paid "per line of code"?
Admin
just what i was thinking! *nod*nod*
Admin
LMAO - I'm going to steal that joke and reuse it on some jnr programmers where I work [Y]
Admin
What I want to know is why does the code need to simulate a button click as part of the header initialisation. You can explain the rest of it as being generated code, but why the click?
Admin
Paula Bean is back. Brilliant!!
Admin
I agree. It would make more sense to just set the value:
document.getElementById(<FONT color=#990000>'btnChkRslts'</FONT>).checked = true;
Admin
Why is everyone assuming that this is a checkbox. The prefix "btn" would suggest button to me in which case a click makes sense..
Admin
Many years ago, I was writing a hard-core Real-Time aviation software for a fighter-jet. We used to pull all sorts of tricks to gain ANY improvement in speed-performance. One day, I found the following snippet of code, in a larger function, not once but three times: Assuming a table of flags that only one of which was ever set to true (there actually was a reasonably good reason to have an array of flags, instead of just saving the index), and a range-checked index x set elsewhere:
I was trying to understand this code, and spent a long time trying to figure out what the bloody catch was. I mean, there just HAD to some reason to write the code this way, right? After consulting three other engineers, I replaced it with:
So much for efficiency, eh? Neat community. I just joined, after seeing yesterday's horror.