Comment On Time Flies

Alan's supervisor forwarded him a curious ticket - a recently hired employee was training on how to use the customer profile web page and the new user felt that that the countdown timer on the page wasn't behaving quite right. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Time Flies

2012-12-12 08:12 • by ColdHeart (unregistered)
Ahh, the wonders of bugs turning into features...

Re: Time Flies

2012-12-12 08:16 • by 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.

Re: Time Flies

2012-12-12 08:18 • by johnckirk
if(msec==100)

{
msec=0
sec--
}


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

Re: Time Flies

2012-12-12 08:20 • by Frank (unregistered)
What happened to the zeroth comment?

Re: Time Flies

2012-12-12 08:23 • by 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?

Re: Time Flies

2012-12-12 08:26 • by Rodnas (unregistered)
396952 in reply to 396950
Frank:
What happened to the zeroth comment?


you mean the zreoth comment.

Re: Time Flies

2012-12-12 08:27 • by Myself (unregistered)
setTimeout(func(),1) ??

setTimeout(func(),1000) ??

Re: Time Flies

2012-12-12 08:27 • by Rodnas (unregistered)
"Time flies like an arrow, fruit flies like a banana" - G. Marx

Re: Time Flies

2012-12-12 08:29 • by letatio (unregistered)
Who the hell indents like that?

Re: Time Flies

2012-12-12 08:34 • by Pietie (unregistered)
"Time flies like an arrow. Time birds like a bullet." - ??

Re: Time Flies

2012-12-12 08:34 • by Jeff (unregistered)
396958 in reply to 396955
An indentured servant?

Re: Time Flies

2012-12-12 08:35 • by 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).

Re: Time Flies

2012-12-12 08:35 • by Zreoth (unregistered)
396960 in reply to 396952
Rodnas:
Frank:
What happened to the zeroth comment?


you mean the zreoth comment.

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

Re: Time Flies

2012-12-12 08:36 • by silverwizard (unregistered)
396961 in reply to 396958
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.

Re: Time Flies

2012-12-12 08:37 • by Bring Back Nagesh (unregistered)
396962 in reply to 396955
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.

Re: Time Flies

2012-12-12 08:42 • by Oscar (unregistered)
396963 in reply to 396959
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.

Re: Time Flies

2012-12-12 08:56 • by Mark Bowytz
396964 in reply to 396961
Actually, I'm closer to an implementation of ELIZA.

Re: Time Flies

2012-12-12 08:58 • by dkf
396965 in reply to 396955
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)…

Re: Time Flies

2012-12-12 09:02 • by 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?

Re: Time Flies

2012-12-12 09:10 • by 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.

Re: Time Flies

2012-12-12 09:13 • by g (unregistered)
396968 in reply to 396966
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).

Re: Time Flies

2012-12-12 09:18 • by 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...

Re: Time Flies

2012-12-12 09:27 • by Doctor_of_Ineptitude (unregistered)
396971 in reply to 396959
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.

Re: Time Flies

2012-12-12 09:27 • by RichP
396972 in reply to 396948
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.

Re: Time Flies

2012-12-12 09:30 • by Steve The Cynic
396973 in reply to 396964
Mark Bowytz:
Actually, I'm closer to an implementation of ELIZA.

It's better than being like PARRY, I suppose...

Re: Time Flies

2012-12-12 09:32 • by 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.

Re: Time Flies

2012-12-12 09:33 • by Singular (unregistered)
396975 in reply to 396972
RichP:
No maths required.
Yes, but if maths were allowed, could you do it using only three of them?

Re: Time Flies

2012-12-12 09:41 • by Code Slave
396976 in reply to 396955
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.

Re: Time Flies

2012-12-12 09:55 • by TGV
396977 in reply to 396954
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).

Re: Time Flies

2012-12-12 10:09 • by Andrew (unregistered)
396979 in reply to 396972
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

Re: Time Flies

2012-12-12 10:42 • by Daniel (unregistered)
396981 in reply to 396971
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.

Re: Time Flies

2012-12-12 10:51 • by neminem (unregistered)
396982 in reply to 396977
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.

Re: Time Flies

2012-12-12 10:52 • by redtetrahedron
396983 in reply to 396976
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!

Re: Time Flies

2012-12-12 11:05 • by Mark (unregistered)
396984 in reply to 396959
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.

Re: Time Flies

2012-12-12 11:07 • by 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.

Re: Time Flies

2012-12-12 11:10 • by Bring Back Nagesh (unregistered)
396986 in reply to 396983
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.

Re: Time Flies

2012-12-12 11:12 • by pjl (unregistered)
Time's fun when you're having flies (say the frogs).

Re: Time Flies

2012-12-12 11:31 • by TRWTF (unregistered)
396988 in reply to 396967
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.

Re: Time Flies

2012-12-12 11:55 • by fwip (unregistered)
396989 in reply to 396983
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.

Re: Time Flies

2012-12-12 12:13 • by redtetrahedron
396990 in reply to 396986
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.

Re: Time Flies

2012-12-12 12:17 • by redtetrahedron
396991 in reply to 396989
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

Re: Time Flies

2012-12-12 12:33 • by Ardik
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 ...

Re: Time Flies

2012-12-12 12:39 • by Mason Wheeler
396993 in reply to 396968
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.

Re: Time Flies

2012-12-12 12:49 • by jay (unregistered)
396994 in reply to 396955
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.)

Re: Time Flies

2012-12-12 12:53 • by foad (unregistered)
396995 in reply to 396991
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.

Re: Time Flies

2012-12-12 12:57 • by jay (unregistered)
396996 in reply to 396947
ColdHeart:
Ahh, the wonders of bugs turning into features...


Re: Time Flies

2012-12-12 12:58 • by da Doctah
396997 in reply to 396992
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".

Re: Time Flies

2012-12-12 13:04 • by old timer (unregistered)
I've written and maintained a lot of FORTRAN over the years. That indenting style is not from FORTRAN.

Re: Time Flies

2012-12-12 13:05 • by jay (unregistered)
396999 in reply to 396993
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.

Re: Time Flies

2012-12-12 13:14 • by Ardik
397001 in reply to 396997
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.
« PrevPage 1 | Page 2Next »

Add Comment