• FF (unregistered)

    This guy clearly had a vision. I bet he still has.

  • Me (unregistered) in reply to FF

    FIFTY-SECOND!!!

    dôh

  • OverloadedOperator (unregistered)

    I think he/she was trying to delay the triggering the button click event. This could have more easily been accomplished by using  a script block at the bottom of the page or by using "window.setTimeout(string object,int milliseconds)". Use the API, Luke!


  • Yakov Smirnoff (unregistered) in reply to erlando

    Ah-hah!!! It's a radio buttton.

  • NewbieCoder (unregistered) in reply to kahnman
    kahnman:
    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:
            int x;
    boolean VideoSources [16];

    for (int i = 0; i < 1; i++) {
    if (i == x && VideoSources[i]) {
    // Do something
    break;
    }
    }

    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:

            if(VideoSources[x]) {
    // Do something
    }

    So much for efficiency, eh? Neat community. I just joined, after seeing yesterday's horror.



    You do realize you could actually replace it with:

    if(VideoSources[0])
    {
    //Do something
    }

    the i < 1 portion of the for loop means that i = 0 is only ever evaluated (unless it's a typo ;) )
  • NewbieCoder (unregistered) in reply to NewbieCoder

    Bah...the last part is suppose to say:

    the i ;&lt 1 part of the for loop causes i = 0 to only ever be evaluated

  • (cs) in reply to kahnman
    kahnman:
    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:
            int x;
    boolean VideoSources [16];

    for (int i = 0; i < 1; i++) {
    if (i == x && VideoSources[i]) {
    // Do something
    break;
    }
    }

    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:

            if(VideoSources[x]) {
    // Do something
    }

    So much for efficiency, eh? Neat community. I just joined, after seeing yesterday's horror.

    Your code blows up if x is too big. The old code does not.

  • (cs) in reply to OverloadedOperator
    Anonymous:
    I think he/she was trying to delay the triggering the button click event. This could have more easily been accomplished by using  a script block at the bottom of the page or by using "window.setTimeout(string object,int milliseconds)". Use the API, Luke!


    Nope, the delay this would create would likely be a fraction of a second, even on a 56k connection.  The line:

    var intCount = 0;

    is hardcoded in the ASP/JSP/HTML/whatever to initialize the value to 0.  The remainder of the code, up to and including intCount = 15, is generated.  I think it's obvious that this person is iterating over something on the server to generate these lines, with the value incremented with every iteration.  Rather than print out the final value, they print all of them.  Kind of goofy but I woulnd't say "WTF!" if I encountered it.
  • Ekevu (unregistered) in reply to Damien
    Anonymous:
    Looks like it might have been some code that leaked out of a code generator.


    Doesn't make a lot of sense. It seems he was looking at its source, not output HTML.
  • (cs) in reply to Ekevu
    Anonymous:
    Doesn't make a lot of sense. It seems he was looking at its source, not output HTML.


    How can you make that determination?
  • Phillip Susi (unregistered) in reply to kahnman

    Did you make a typeo entering this?  x is used uninitialized, therefore, the results are undefined. 

    kahnman:
    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:

            int x;
    boolean VideoSources [16];

    for (int i = 0; i < 1; i++) {
    if (i == x && VideoSources[i]) {
    // Do something
    break;
    }
    }

    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:

            if(VideoSources[x]) {
    // Do something
    }

    So much for efficiency, eh? Neat community. I just joined, after seeing yesterday's horror.

  • (cs)

    So, there was this like bug, see? Where if the user clicks on the button too quickly sometimes the script crashes? So we were like telling users to "count to 15 before you click anything." So Guru guy tells me to fix the bug. Says it's a race conditioner. Whatever. Anyway, I think, well, why not have the computer count to 15 for the user? Bingo. Like, fear my m4d sk177z.

    --Rank

  • Mongoose (unregistered) in reply to Dave Sag

    Anonymous:
    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?

    Auto generate and automagically run the code. Boom!

     

  • Andy (unregistered)

    Uh, i know, i know.

    It was like: Boss talking to his trainee: "Make a loop which counts to 15, and then push the button".
    Trainee was like: "Er, what's a loop sir?"
    Boss said: "Dumb*ss, its counting from 0 to 15 or sumthin!"
    Trainee thought: "Oh, cool, I can do that, I just do it manually!"

  • (cs) in reply to FF
    Anonymous:
    This guy clearly had a vision. I bet he still has.


    Nah, he's taking medication for that now...
  • JakobA (unregistered) in reply to Dave Sag
    Anonymous:
    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?
    I expect the click is to autosubmit a form with browser and user data findable through jevascript. There is a lot of things you cannot query reliably from serverside.
  • (cs) in reply to Hexar

    Jeeez Hexar......

    Why must there always be one chop that has to correct the problem on the forum ?

    We all know how to fix it Hexar...........

  • (cs) in reply to JakobA

    in that case why not use form.submit()

    no this really has me stumped - why would something called headerInit() need to click a button in the page?  I've done a ton of javascript in my time and can't ever recall having to do this.

  • (cs) in reply to Phillip Susi

    kahnman wrote: "and a range-checked index x set elsewhere"

    Phillip Susi wrote " x is used uninitialized, therefore, the results are undefined"

    I think we know who just failed his reading skills roll.

  • bob (unregistered) in reply to ItsAllGeekToMe
    ItsAllGeekToMe:

    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.

    On most systems you can use mapping to do this.
  • Sandeep (unregistered) in reply to bob

    He was just doing typing excercise.

  • Hex Spurt (unregistered) in reply to Sandeep

    I don’t understand this at all it seems strange that someone would use the onload event of the page to simulate a button click which I would assume calls a function of some sort, even if it was server side code that wrote this (which I doubt) it is truly pointless, surely the easiest way would be to write the function call in the onload event if it was needed and remove the button totally. As to it being a delay that too is not possible unless the delay is less than a millisecond

     <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    Someone suggested that s/he was showing off by counting to fifteen that I doubt also as it would have required s/he to remove one of their shoes and I am sure that they would have trouble tying the bow again or replacing their sock without mommies assistance

  • Nick (unregistered) in reply to davesag
    davesag:

    no this really has me stumped - why would something called headerInit() need to click a button in the page?  I've done a ton of javascript in my time and can't ever recall having to do this.


      Why, to click on the pop-up add you obviously wanted to see because Firefox (more or less) only opens the popups you click on.
  • (cs)
    The intCounts, they do nothing!

    Yes, I really missed that one in this thread.
  • Pete (unregistered) in reply to danhash
    Anonymous:
    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.

    In that case, it really, really needs a comment saying so. Personally, I go with the generated HTML explanation - that can produce some really weird-looking stuff on the client side even without notable WTFery.

    Pete

  • K (unregistered) in reply to Mung Kee

    Mung Kee:
    Anonymous:
    I think he/she was trying to delay the triggering the button click event. This could have more easily been accomplished by using  a script block at the bottom of the page or by using "window.setTimeout(string object,int milliseconds)". Use the API, Luke!


    Nope, the delay this would create would likely be a fraction of a second, even on a 56k connection.  The line:

    var intCount = 0;

    is hardcoded in the ASP/JSP/HTML/whatever to initialize the value to 0.  The remainder of the code, up to and including intCount = 15, is generated.  I think it's obvious that this person is iterating over something on the server to generate these lines, with the value incremented with every iteration.  Rather than print out the final value, they print all of them.  Kind of goofy but I woulnd't say "WTF!" if I encountered it.

     

    I agree. He may have had two reasons to output the count.

    1. To avoid timeouts. It may (only a guess here) cause problems for some browsers if they have to wait too long. I doubt it, but it may be possible.
    2. Debug reasons.

    But if I had to generate a click, I would have moved the if-test to the server, and generated the click-event myself

  • Jim (unregistered)

    Has a problem with null object and found that pausing during de-bug caused it to work then light bulb came on and said "If I could only pause for a few seconds while the objects were created"

    Only a guess

  • Joe (unregistered) in reply to Jim

    No no no.
    Here's what's going on;

    "Optimise" JavaScript code taking advantage of the fact a function can access all local variables in the scope of the caller.
  • (cs) in reply to ItsAllGeekToMe

    actually, with some HTTP servers (certainly with Apache) you can define how to handle files of any extension.  You can have it send .wtf files to be parsed by PHP if you really wanted to...  Hmm.. that gives me an idea!

  • (cs)

    This was done for job security reasons. The original version looked like this:

    intCount=1

    intCount=2

    intCount=3

    intCount=4

    intCount=5

    ...

    intCount=9997

    intCount=9998

    intCount=9999

    intCount=10000

     

    but when the customers kept complaining that it was too slow, he would go back and remove some of the lines. As you can see, there's still room for further optimization.

  • (cs) in reply to Phillip Susi
    Anonymous:
    Did you make a typeo entering this?  x is used uninitialized, therefore, the results are undefined. 

    kahnman:
    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:
            int x;
    boolean VideoSources [16];

    for (int i = 0; i < 1; i++) {
    if (i == x && VideoSources[i]) {
    // Do something
    break;
    }
    }

    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:

            if(VideoSources[x]) {
    // Do something
    }

    So much for efficiency, eh? Neat community. I just joined, after seeing yesterday's horror.



    there have been 2-3 people who have mentioned if x is out of range, or the fact that x is undefined - but if you read his description in there it says 'a range-checked index x set elsewhere'. the definition of x is included so you know its type....

  • c-- (unregistered) in reply to Malhar

    I think you'r right!
    There are obviously very good for loops that generate such code.
    So there.

  • Dragos (unregistered)

    The repeating incremental value assignments may be the result of a misfired editor macro. My 2c.

Leave a comment on “Not Trusting a For-Loop?”

Log In or post as a guest

Replying to comment #:

« Return to Article