- 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
Ahh, the wonders of bugs turning into features...
Admin
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.
Admin
I always thought that there were 1000 milliseconds in a second.
Admin
What happened to the zeroth comment?
Admin
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?
Admin
you mean the zreoth comment.
Admin
setTimeout(func(),1) ??
setTimeout(func(),1000) ??
Admin
"Time flies like an arrow, fruit flies like a banana" - G. Marx
Admin
Who the hell indents like that?
Admin
"Time flies like an arrow. Time birds like a bullet." - ??
Admin
An indentured servant?
Admin
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).
Admin
Admin
And now we see that Mark is just a web page, silently generating WTFs for us to read.
Admin
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.
Admin
Admin
Actually, I'm closer to an implementation of ELIZA.
Admin
Admin
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?
Admin
msec++ if(msec==100) { msec=0 if(sec==0) { sec=59 min-- } else { sec-- }
Seems like the correct version didn't need much changing.
Admin
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).
Admin
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...
Admin
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.
Admin
Pshaw. Your code was clearly doing: if (timer == 0) ... The fix was clearly: if (timer <= 0) ...
No maths required.
Admin
Admin
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.
Admin
Admin
My co-worker... they could definitely benefit from a slight tap on the cranium with the clue-bat.
Admin
Admin
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
Admin
Eventually, but only after first burying this corpse of irrational thought.
Admin
Admin
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!
Admin
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.
Admin
Global Javascript function named "start" and global vars named "min" and "sec". No semi-colons. Indentation is the least of this codes problems.
Admin
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.
Admin
Time's fun when you're having flies (say the frogs).
Admin
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.
Admin
Admin
This was 11 years ago.. not sure those tools existed back then? I did look, could not find one for free at the time.
Admin
OH! Of course! That's so self-evident and intuitive
/s
Admin
For me
is the funniest part.(As mentioned before by others) why not just
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 ...
Admin
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.
Admin
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.)
Admin
Admin
Admin
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".
Admin
I've written and maintained a lot of FORTRAN over the years. That indenting style is not from FORTRAN.
Admin
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.
Admin