- 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
This post misses the code where it actually triggers this method... Normally AJAX calls don't trigger scripts to run again unless this method is called in the oncomplete callback.
The code is still ugly tho..
Admin
Amazingly no one thought to store the time in an integer, as seconds. Variable rate of decrement I can live with (think The Doppler Effect), but string manipulation? Guffah and Inexcusable!
Admin
I don't know AJAX, but using .ToString when working with time must be wrong in pretty much every language.
Captcha: appellatio - a sexual act performed by Mac-zealots
Admin
How to spot someone who doesn't understand javascript, without even looking:
The callback right there? That's an eval() in disguise. It's ugly and discouraged, it doesn't play nice with strict mode, it prevents the JS interpreter from optimizing or JITing, it prevents strong minification.. and it's entirely pointless. Just pass the function directly:
Anytime you spot some javascript that uses strings as callbacks, you know the coder hasn't refreshed his knowledge since the 90s, and probably shouldn't be near a keyboard. I think the example in the article proves that point.
Admin
At least he included the base argument with every parseInt call.
Admin
It could have been written in the nineties.
Admin
No, they figure out how to properly signal when things are done, and don't use sleep as a crutch.
Admin
Admin
Modal dialogs in the 90s were called window.alert().
Admin
But it is beside the point - this is not .NET code, this is Javascript.
Admin
Admin
I still fail to see a major wtf, though - runLogoutClock() is called once when the webpage is loaded (being in the global namespace) and then only everytime window.setTimeout() calls it. It is not automagically called on AJAX calls.
The string stuff is ugly but a minor wtf.
Accurracy might not be great, but for an automated log off, who cares if instead of after 10 minutes log off happens after 10:42 or premature at 9:58?
What's missing is the reset to 10 minutes once the user does something, but that can happen elsewhere since the counter is not a javascript variable but the (string)inner html of an element.
So yeah, a bit ugly, but who cares. A quick-and-dirty automatic log off.
Admin
It is not surprising that programmers have problems with time. Even Nobel prize winners don't know what time is, except "that thing which prevents everything from happening instantaneous" (which would be bad in so many ways).
Captha: Jumentum - things that are happening just this moment.
Admin
Clearly you don't know AJAX, because it isn't a language.
Admin
Admin
But but... Just yesterday I got yelled at for saving a phone number as an integer instead of as a string? Oh, this programming stuff is hard to do!
Admin
Using an integer for a telephone number is genuinely a bad idea because, at least where I live, telephone numbers start with 0 (domestic) or 00 (international). Integers reliably don't record leading 0s.
On the original problem anyone vaguely sane would check that the session was not timed out when somebody requested some information or pressed a form submit button. The whole approach is WTF.
If you want hard programming try writing a parallel program framework where you have to concentrate on both getting the details right and preserving the properties your deadlock freedom proof requires simultaneously.
Admin
Admin
Can you do math with time?
Can you do math with phone numbers?
That's the difference.
Admin
I can feel alone and taste beer, at the very least.
Admin
Yes, you can smell something without breathing. Take something smelly, hold your breathe and then waft it under your nose. You will still smell it as the aroma chemicals move into your nose. You smell in your nose, not your lungs.
This is a common trick for chemists to smell something without taking a lung full of (potentially harmful) chemicals.
Admin
Admin
Admin
Admin
Admin
Admin
It can be done without sleep. That is point previous poster is trying to prove.
Admin
If we want to figure out when processing a file is done, then yes we should wait for an "I'm done processing this file" signal instead of polling it with sleeps in between.
But if the signal is "a second has passed", as it would be when implementing a countdown timer, then sleep is exactly what we want. Then we check the actual time so that if 1.1 actual seconds have passed then we know to ask for a "0.9 seconds have passed" signal next time.
Admin
Except that it can't unless that is the ONLY thing you want the browser to do.
Admin
Frist (but appearing last due to temporal distortion)
Admin
If the setTimeout method were a real, synchronous sleep command, it would be easier and maybe it would work (it'd still be awful code). But in fact that's not what I'd call sleep, it is just setting an event handler (like pretty much everything you do in Javascript). Lots of things can happen in the meantime (i.e. other code doing stuff) so you shouldn't rely on it running neatly in 1s intervals and everything staying the same in between.
Admin
Sure, it's called alarm() and signal()
captcha: pecus - pecaus I can read man pages
Admin
snoofle for president!
Admin
Feel something without touching: A nice fire Taste something without eating: "That leaves a bad taste in my mouth" Hear something without listening: Wife?
So there you go!
Admin
Admin
TRWTF is thinking that the data should be held in a control instead of simply displayed there. That was the developer's first mistake.
Admin
I'm sorry: this is written in ASP.NET, using default controls with the default naming convention, as far as we can see it imports an entire js framework to get access to one function ($find), it performs string manipulation to decrement a value, and it uses client side code to attempt to implement a "security" feature - but your biggest issue with it is storing data in a control?!
tbh, I wouldn't be at all surprised to find that getComputedStyle(document.getElementById('ctl00_lblTimer')) had a display:none; declaration in there somewhere: the existence of "ctl00_lblWaitClock" and "runWaitForClock()" send shivers down my spine.
Although as already noted, setTimeout() is a very poor substitute for a properly implemented sleep, and I'd be frankly amazed if this code actually worked in any meaningful way...
Admin
I'm sorry, you think that default names will open the gates to hell?
Admin
Admin
Admin
Admin
Admin
Admin
A) Much better article snoofle B) That'sthe first I've seen Nagesh for a while, and his Engrish has improved markedly
Admin
Programming is hard! Let's go shopping!
Admin
timers are not easy ... some jquery stopwatch plugin for instance was too stupid to get it right (they slept for 960ms which caused the clock to run faster until 1000 and 960 sync up again which would cause the clock to stall)
Admin
What is faster (decrementing a string "9:59" or transforming 599 into "9:59") I don't know but you would probably not gain much.
Admin
Well, I have personal experience of watching client side code break horribly between a test server deployment and a live server deployment due to ASP.NET default naming and unnamed containing controls. Both servers had identical configurations, as far as anyone could tell. Trying to resolve it felt like I'd been at least dragged into Purgatory, if not Hell itself...
Any time your client side code relies on server-side automagical naming, you're asking for trouble. How hard is it to name the containing control yourself?
Although frankly, anyone who uses Webforms as is deserves throwing into hell anyway. IMNSHO, of course.
Admin
There are no real WTFs in today's code (well, except for the bizarre white-bold-italics-on-red that was used for the single-quoted strings).
Using setTimeout("runLogoutClock()", 1000) instead of setTimeout(runLogoutClock, 1000) falls under "good enough". It works, the overhead is negligible (you're only executing it once per second, for fuck's sake; that is an eternity to the computer).
Yes, it's true that the clock won't run at exactly one second per tick, but there's absolutely no reason to be worried about it drifting a few milliseconds. It's a logout timer; high precision is not necessary.
The only possible reason this could be a WTF would depend on the code that calls runLogoutClock, because the way it's written, it can't be called more than once or your clock will be decremented more than once per second.
Admin
More to the point, regardless of what language you are using, if you want millisecond resolution, you need a real-time operating system, which is something most people aren't running.