• ColdHeart (unregistered)

    Ahh, the wonders of bugs turning into features...

  • Andrew (unregistered)

    I once had to work on a system where the timing for a scheduled execution was done by subtracting 900 from a counter. The counter was initialized to 86400 (total seconds in 24h), and every 15mins it subtracted 900 from that number.

    Reaching zero didnt necessarily mean it actually executed; the condition's sometimes slipped to FALSE and the counter went far into the negatives.

    Resetting timing involved working out how many 15min increments we were away from what was considered 'scheduled' execution time. I managed to replace it, at least.

  • (cs)
    if(msec==100)
    {
    msec=0
    sec--
    }

    I always thought that there were 1000 milliseconds in a second.

  • Frank (unregistered)

    What happened to the zeroth comment?

  • Ralph (unregistered)

    Instead of futzing around with the status bar, wouldn't it be more in keeping with modern script usage and GUI design to have the timer appear in a pop-up every second? Besides, that would make the page "more interactive" which is always a good thing right?

  • Rodnas (unregistered) in reply to Frank
    Frank:
    What happened to the zeroth comment?

    you mean the zreoth comment.

  • Myself (unregistered)

    setTimeout(func(),1) ??

    setTimeout(func(),1000) ??

  • Rodnas (unregistered)

    "Time flies like an arrow, fruit flies like a banana" - G. Marx

  • letatio (unregistered)

    Who the hell indents like that?

  • Pietie (unregistered)

    "Time flies like an arrow. Time birds like a bullet." - ??

  • Jeff (unregistered) in reply to letatio

    An indentured servant?

  • Kent (unregistered)
    You see, early on, there was a bunch of deadlocking as it gained more widespread use. So, to make sure that users kept their time to a minimum, I added a sense of urgency
    Code smell is often merely a hint emanating from the buried corpse of rational thought. When the brave, armed with suitable quantities of holy water, detect code smell and pursue it to its source, the genesis of abomination is likely to be found.

    If your database is having deadlock problems, the solution is to give users 40 minutes (your mileage may vary) to submit the form?

    First of all, deadlocks arise from two (ignorantly written) updates occurring at roughly the same time. Not 40 minutes apart.

    Second, if your database is lumbering under the burden of 100 updates per day, the solution is not to prod the users to submit 100 updates faster. I'll leave it to the geniuses who haunt this board to work out The Real Answer but That's Not It (TM).

  • Zreoth (unregistered) in reply to Rodnas
    Rodnas:
    Frank:
    What happened to the zeroth comment?

    you mean the zreoth comment.

    Sorry, I was busy. Now that I'm not Frist, though...

  • silverwizard (unregistered) in reply to Jeff
    The Full Article:
    To be sure, yes, i was a web page

    And now we see that Mark is just a web page, silently generating WTFs for us to read.

  • Bring Back Nagesh (unregistered) in reply to letatio
    letatio:
    Who the hell indents like that?
    Probably the same kind of person who thinks there are 59 seconds in a minute, and thinks the browser, let alone the operating system, can keep up with timer events at a granularity of 1ms and remain accurate.

    Captcha: validus - both the above assumptions will become validus in the future, as computers become even faster, and the economy gets so bad that we have to sell our zeroth second to China.

  • Oscar (unregistered) in reply to Kent
    Kent:
    if your database is lumbering under the burden of 100 updates per day
    I missed the part where they said it was running under Peoplesoft.
  • (cs) in reply to silverwizard

    Actually, I'm closer to an implementation of ELIZA.

  • (cs) in reply to letatio
    letatio:
    Who the hell indents like that?
    I used to work with someone who indented like that. As far as I could work out, it was a style they learned when they started out on FORTRAN (but I don't know which version, 66 or 77)…
  • mike5 (unregistered)

    Implementing a countdown timer by separating the time into hours, minutes and seconds? And then writing convoluted (and erroneous) logic to count down to zero?

    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?

    So people know how to debug deadlocks, but are unable to perform simple arithmetics?

  • ColdHeart (unregistered)

    msec++ if(msec==100) { msec=0 if(sec==0) { sec=59 min-- } else { sec-- }

    Seems like the correct version didn't need much changing.

  • g (unregistered) in reply to mike5
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    In some web-survey code I inherited I found code which measured the time people took for each question with setTimeout(function() { time += 1},1); And divided the resulting time by 100 to get the number of seconds, I guess they used 100 just to get the values to "look" right.

    It looked right(ish) due to most browser's timer-resolution being around 10ms (they're mostly in the 4-16ms range).

  • urza9814 (unregistered)

    Alan apparently didn't watch the timer very long, since he missed the part where at 5 minutes remaining it resets to 40 and stops counting down...

    Wish the timer for our internal pages did that. It's got a five minute timeout. So obnoxious...

  • Doctor_of_Ineptitude (unregistered) in reply to Kent
    Kent:
    You see, early on, there was a bunch of deadlocking as it gained more widespread use. So, to make sure that users kept their time to a minimum, I added a sense of urgency
    Code smell is often merely a hint emanating from the buried corpse of rational thought. When the brave, armed with suitable quantities of holy water, detect code smell and pursue it to its source, the genesis of abomination is likely to be found.

    If your database is having deadlock problems, the solution is to give users 40 minutes (your mileage may vary) to submit the form?

    First of all, deadlocks arise from two (ignorantly written) updates occurring at roughly the same time. Not 40 minutes apart.

    Second, if your database is lumbering under the burden of 100 updates per day, the solution is not to prod the users to submit 100 updates faster. I'll leave it to the geniuses who haunt this board to work out The Real Answer but That's Not It (TM).

    If you had read the article, you would have realized that the original coder had realized and fixed the deadlocks. So you can take your snobbish Real Answer and basically *uck it.

  • (cs) in reply to Andrew
    Andrew:
    I once had to work on a system where the timing for a scheduled execution was done by subtracting 900 from a counter. The counter was initialized to 86400 (total seconds in 24h), and every 15mins it subtracted 900 from that number.

    Reaching zero didnt necessarily mean it actually executed; the condition's sometimes slipped to FALSE and the counter went far into the negatives.

    Resetting timing involved working out how many 15min increments we were away from what was considered 'scheduled' execution time. I managed to replace it, at least.

    Pshaw. Your code was clearly doing: if (timer == 0) ... The fix was clearly: if (timer <= 0) ...

    No maths required.

  • (cs) in reply to Mark Bowytz
    Mark Bowytz:
    Actually, I'm closer to an implementation of ELIZA.
    It's better than being like PARRY, I suppose...
  • anonymouse (unregistered)

    It's not the "speed of the computer", it's that setTimeout has a minimum time associated with it.

    setTimeout("start()",1)

    I believe it used to be a 30ms minimum and anything below would default to that. I think chrome does 15ms, not sure on the others anymore.

  • Singular (unregistered) in reply to RichP
    RichP:
    No maths required.
    Yes, but if maths were allowed, could you do it using only three of them?
  • (cs) in reply to letatio
    letatio:
    Who the hell indents like that?

    My co-worker... they could definitely benefit from a slight tap on the cranium with the clue-bat.

  • (cs) in reply to Rodnas
    Rodnas:
    "Time flies like an arrow, fruit flies like a banana" - G. Marx
    And of course: time flies with a stop watch (Hint: it's an imperative).
  • Andrew (unregistered) in reply to RichP
    RichP:
    Andrew:
    I once had to work on a system where the timing for a scheduled execution was done by subtracting 900 from a counter. The counter was initialized to 86400 (total seconds in 24h), and every 15mins it subtracted 900 from that number.

    Reaching zero didnt necessarily mean it actually executed; the condition's sometimes slipped to FALSE and the counter went far into the negatives.

    Resetting timing involved working out how many 15min increments we were away from what was considered 'scheduled' execution time. I managed to replace it, at least.

    Pshaw. Your code was clearly doing: if (timer == 0) ... The fix was clearly: if (timer <= 0) ...

    No maths required.

    Firstly: MY code?! I was the one who had to support it! Plus it was a major effort to convince people that it needed changing.

    Also: You're assuming the condition execute was "Counter less than zero". There were other conditions in play.

    So no. There was no timer <= 0

  • Daniel (unregistered) in reply to Doctor_of_Ineptitude
    Doctor_of_Ineptitude:
    Kent:
    You see, early on, there was a bunch of deadlocking as it gained more widespread use. So, to make sure that users kept their time to a minimum, I added a sense of urgency
    Code smell is often merely a hint emanating from the buried corpse of rational thought. When the brave, armed with suitable quantities of holy water, detect code smell and pursue it to its source, the genesis of abomination is likely to be found.

    If your database is having deadlock problems, the solution is to give users 40 minutes (your mileage may vary) to submit the form?

    First of all, deadlocks arise from two (ignorantly written) updates occurring at roughly the same time. Not 40 minutes apart.

    Second, if your database is lumbering under the burden of 100 updates per day, the solution is not to prod the users to submit 100 updates faster. I'll leave it to the geniuses who haunt this board to work out The Real Answer but That's Not It (TM).

    If you had read the article, you would have realized that the original coder had realized and fixed the deadlocks. So you can take your snobbish Real Answer and basically *uck it.

    Eventually, but only after first burying this corpse of irrational thought.

  • neminem (unregistered) in reply to TGV
    TGV:
    Rodnas:
    "Time flies like an arrow, fruit flies like a banana" - G. Marx
    And of course: time flies with a stop watch (Hint: it's an imperative).
    My favorite creative misparsing of the statement "time flies like an arrow" is, "measure the timing of flies in the same way that an arrow would measure that timing", though yes, "measure the timing of flies in the same way that you would measure the timing of an arrow" is also a legitimate (if equally inappropriate semantically) parse.
  • (cs) in reply to Code Slave
    Code Slave:
    letatio:
    Who the hell indents like that?

    My co-worker... they could definitely benefit from a slight tap on the cranium with the clue-bat.

    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!

  • Mark (unregistered) in reply to Kent
    Kent:
    Code smell is often merely a hint emanating from the buried corpse of rational thought. When the brave, armed with suitable quantities of holy water, detect code smell and pursue it to its source, the genesis of abomination is likely to be found.

    If your database is having deadlock problems, the solution is to give users 40 minutes (your mileage may vary) to submit the form?

    First of all, deadlocks arise from two (ignorantly written) updates occurring at roughly the same time. Not 40 minutes apart.

    Second, if your database is lumbering under the burden of 100 updates per day, the solution is not to prod the users to submit 100 updates faster. I'll leave it to the geniuses who haunt this board to work out The Real Answer but That's Not It (TM).

    There are a couple ways I interpret this article beyond how the developer described the problem or how the support engineer interpreted what he said. I think that, given the intent of the code, there was no lock at all and it was last in wins so that stale values on a web form the user kept open all day would overwrite new values. Or, there was actually a lock and it was perpetual until the user submitted the form. Either way, still pretty bad.

  • Mark (unregistered)

    Global Javascript function named "start" and global vars named "min" and "sec". No semi-colons. Indentation is the least of this codes problems.

  • Bring Back Nagesh (unregistered) in reply to redtetrahedron
    redtetrahedron:
    Code Slave:
    letatio:
    Who the hell indents like that?

    My co-worker... they could definitely benefit from a slight tap on the cranium with the clue-bat.

    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!

    Wow, you would make an excellent salesman. You managed to convince your boss to spend money on a tool that only half-works, whereas if you'd done some research, you could have got a much better tool for free.

    Eclipse (with the web developers plugins) is one such product that can format JS source code without semicolons, plus it will highlight all the places where they should be, among other potential programming problems. Heck, even jsFiddle will do it for you, plus it comes with JSLint.

  • pjl (unregistered)

    Time's fun when you're having flies (say the frogs).

  • TRWTF (unregistered) in reply to ColdHeart

    The correct version actually shouldn't count on javascript timeout to increment a timer, since timeout is not accurate (It blocks on quite a few things and just queues up). A correct timer saves the start time, and the timeout just updates the timer using the current time and the start time to find out how long it has run.

  • fwip (unregistered) in reply to redtetrahedron
    redtetrahedron:
    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!
    Step 1. vim code.js Step 2. gg=GZZ Step 3. That was all the steps, you're done already.
  • (cs) in reply to Bring Back Nagesh
    Bring Back Nagesh:
    redtetrahedron:
    Code Slave:
    letatio:
    Who the hell indents like that?

    My co-worker... they could definitely benefit from a slight tap on the cranium with the clue-bat.

    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!

    Wow, you would make an excellent salesman. You managed to convince your boss to spend money on a tool that only half-works, whereas if you'd done some research, you could have got a much better tool for free.

    Eclipse (with the web developers plugins) is one such product that can format JS source code without semicolons, plus it will highlight all the places where they should be, among other potential programming problems. Heck, even jsFiddle will do it for you, plus it comes with JSLint.

    This was 11 years ago.. not sure those tools existed back then? I did look, could not find one for free at the time.

  • (cs) in reply to fwip
    fwip:
    redtetrahedron:
    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!
    Step 1. vim code.js Step 2. gg=GZZ Step 3. That was all the steps, you're done already.

    OH! Of course! That's so self-evident and intuitive

    /s

  • (cs)

    For me

      go=setTimeout("start()",1)
      [...]
      if(msec==100)
    is the funniest part.

    (As mentioned before by others) why not just

      setTimeout("start()",1000)
    and drop msec completely?! Would've resulted in a quite accurate result with any client (apart from skipping "0", of course).

    A timeout of 1 msec doesn't work in any browser.

    Probably that developer did some trial and error which timing somewhat fits the clock and based on that decided that 1 second has 100 msecs.

    btw: I'm not surprised this went unnoticed for several years. In my experience most users aren't aware that something like a status bar even exists, let alone watch a countdown timer there. They'll notice the 5-minutes-alert, though, and therefore this thing worked as intended ...

  • (cs) in reply to g
    g:
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.

  • jay (unregistered) in reply to letatio
    letatio:
    Who the hell indents like that?

    At my last job, my boss established a company standard that we were NOT ALLOWED to change indenting of existing lines of code. So if, for example, you added an IF statement that encompassed an existing block of code, you couldn't move those lines to the right to line up under the IF. The stated reason for this was that when we committed code to the library, this would make those lines look changed when they really weren't.

    (Of course, we were using SVN, which has a flag to say whether changes in spacing should show up as changed lines in output, so basically his problem was that he didn't want to have to check a box.)

  • foad (unregistered) in reply to redtetrahedron
    redtetrahedron:
    fwip:
    redtetrahedron:
    At a previous job, I inherited a javascript app with 15K-line files from a fired co-worker who had a completely haphazard indenting style, enough to make the code virtually unreadable. Also - there were no semicolons ending the lines, just like this code. I convinced my supervisor to buy a code-reformatting tool, but before I could use it, I still had to add semicolons to the end of each statement before the reformatting tool would be able to parse the code. Ugh!
    Step 1. vim code.js Step 2. gg=GZZ Step 3. That was all the steps, you're done already.

    OH! Of course! That's so self-evident and intuitive

    /s

    I missed the part where you were guaranteed that everything in life would be easy and require no knowledge or thought on your part.

  • jay (unregistered) in reply to ColdHeart
    ColdHeart:
    Ahh, the wonders of bugs turning into features...
    [image]
  • (cs) in reply to Ardik
    Ardik:
    (As mentioned before by others) why not just
      setTimeout("start()",1000)
    and drop msec completely?! Would've resulted in a quite accurate result with any client (apart from skipping "0", of course).

    A timeout of 1 msec doesn't work in any browser.

    Probably that developer did some trial and error which timing somewhat fits the clock and based on that decided that 1 second has 100 msecs.

    Everyone is making the totally unwarranted assumption that "msec" in the OP's code is supposed to stand for "millisecond". It's not. In this context, it's "minisecond".

  • old timer (unregistered)

    I've written and maintained a lot of FORTRAN over the years. That indenting style is not from FORTRAN.

  • jay (unregistered) in reply to Mason Wheeler
    Mason Wheeler:
    g:
    mike5:
    Not like (hours = timeInSecods / 3600 ), and minutes = (timeInSeconds % 3600 ) / 60 and seconds = (timeInSeconds % 60) ?
    hours = Math.floor(timeInSeconds / 3600);
    minutes = Math.floor((timeInSeconds % 3600) / 60);
    
    Division in javascript results in floats

    Division in any sane language results in floats. (Or fractions, if your language does that.) It's simple mathematics. If you can say 5/2 and get 2 as a result, there's something wrong with your language.

    Right, because who could possibly imagine a real-world problem in which an answer involving a fraction is not valid? Like, we have 5 people in our department and 2 offices. How many should we put in each office? Funny how last time we had this problem, the productivity of the guy we cut in half really fell off, and there was an unexplainable dip in the morale of the other four.

  • (cs) in reply to da Doctah
    da Doctah:
    Ardik:
    (As mentioned before by others) why not just
      setTimeout("start()",1000)
    and drop msec completely?! Would've resulted in a quite accurate result with any client (apart from skipping "0", of course).

    A timeout of 1 msec doesn't work in any browser.

    Probably that developer did some trial and error which timing somewhat fits the clock and based on that decided that 1 second has 100 msecs.

    Everyone is making the totally unwarranted assumption that "msec" in the OP's code is supposed to stand for "millisecond".
    Not me!
    da Doctah:
    It's not. In this context, it's "minisecond".
    csec would've been more appropriate then.

Leave a comment on “Time Flies”

Log In or post as a guest

Replying to comment #:

« Return to Article