- 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
Ah, VBScript; empowering an entire generation of hack developers that know nothing about good practices.
I shudder at the thought there are STILL clueless morons out there relying on Classic ASP and VBScript to power their websites.
Admin
Innovate method of overcoming max interval on timers of ~65secs, no, wait...
Admin
Well, it works, right? And don't we keep hearing the old saying "Never change a running system."?!?
Admin
This looks like it came from the old TDWTF coding competitions. I believe there was an entry that was a "simple" calculator front-end that worked just like this to offload all calculations to a SQL engine rather than actually doing math itself.
Admin
Unscrewing a Philips screw with a flathead screwdriver is no problem.
Trying to unscrew a flathead screw with a Philips screwdriver - now I'd like to so somebody do THAT.
Admin
After reading this, I hit Random Article, and what came up was http://thedailywtf.com/Articles/Raymond_Chen_on_Sleep()Deprivation.aspx
Are you sure TDWTF isn't an AI?
Admin
Well, she clearly had the right tools available to add a delay to the process!
The development process, that is
Admin
that's easy. I'd just need one or two extra ingredients. like some bondo, superglue, or a tig welder.
Admin
Wow, I never realized it was even possible to create a sleep function that is susceptible to sql inject.
Admin
It's not totally a WTF to use the database to implement sleeps for the following reasons:
We can modify the database procedure more easily than the code. Or we can get the procedure to look up in a table how it sleeps. So what we put in might not be actual seconds but some other factoring. It could even differ for different versions.
Our database will know we are sleeping and not busy for a while so can get on with doing some lengthy task it will only perform when idle.
We'll be able to store in the database an accurate log of all the sleeps.
It doesn't matter if it's slow, we're trying to be slow anyway...
Of course if none of the first 3 conditions exist...
Admin
Ummmm... WOW! Someone actually took the time to write that much code, write scaffulding code (just in case the HTML was not already broken) and presumably test it. And this ENTIRE TIME... it never occured to them ... not once ... that there might (perhaps) be a better way of going about it? If they decided to kill themselves, I wonder how long they would spend taking toe nail clippers to their necks before they realized there might be a more expedient way of going about that too?
Admin
Admin
Admin
Admin
Meh. Sleep() is overrated.
Admin
The code is completely legit. We use similar thing to get current time: "select now()" - the thing is, users can change time on their machine. Even while application is running. By using "select now()" we have always correct, server time. Same way for pauses. Do not underestimate ingeniousness of your users.
Admin
Admin
Well, don't underestimate the ingeniousness of your sysadmins either. What if your application runs on the sort of server where a minute can last several hours? I'm not kidding: (there was a URL here but it didn't get past spam control)
Admin
This is the famous "I don't know how to do it in <programming language> so I'm doing it in <database engine> instead". We had a developer perform 128-bit DES encryption in Oracle, invoked from Java, that way.
Yes, 128-bit DES. That's not a typo.
Admin
Admin
I doubt it is a waste of SQL resources too much.
Suppose you have a server and clients with user management control, so one end user cannot hog too many resources.
Thus between each transaction they perform, they have to do a Sleep. The client program sends in a number to suggest the length of the sleep based on what the client-side is doing at this point. The server side can override this value and sleep for shorter or longer.
Using SQL and going over the network is generally slow - yes - but here it is clear we are not looking for improved speed, we are purposely trying to slow things down.
Admin
Did you know, by the way, that holes are round because a round lid cannot fall in, whereas a square lid could fall through into the square hole if you align the edge with the diagonal (unless it is very thick, which is unlikely).
Admin
Sure, it can vary from scenario to scenario, but assuming it's a PL/SQL heavy environment (and what Oracle environment isn't), being able to call a procedure like that from any app that can connect to the database is powerful stuff. Single point of maintenance, no DLLs, and it runs on the database server.
Admin
Admin
Those "tools" to solve this problem: http://support.microsoft.com/kb/212667
Method 1 is a busywait. Bad idea on a multiuser web application as it will restrict you to n simultaneous requests where n= processor count.
Method 2 is a non-starter. You can't call external API functions in VBScript. You would have to create a VB6 ActiveX object to export the Sleep function.
Method 3: Using the OnTime Method relies on Microsoft Word as the host.
Given the requirement "Implement a delay on this request" (A valid use-case would be password validation), and a presumed limitation "You can't create a helper DLL, and we need this ASAP", this would be a more than reasonable way to solve the problem - it would actually be the best way.
Of course it is easy for someone who doesn't understand either the requirement or the platform to be snarky.
Admin
Admin
Jest petal to storing. In India, you are be getting them for less than 1200 rupees.
Admin
Given that I am not a native english speaker I went about and checked what a flathead screw is, and apparently, flathead only refers to the shape of the head of a screw, not the tool needed to interact with said screw, so a fladhead screw can be of the phillips variety, so I'd have no issue what so ever with that...
Admin
Admin
I've done that. You have to use just one of the flanges of the crosspoint.
Admin
Admin
Admin
Of course, this only matters if your users would have a reason to maliciously avoid this wait (for example, those "wait 60 seconds before downloading" pages on sites like Rapidshare). If the user wouldn't gain anything by averting the sleep it's really not worth worrying about.
And if interrupting a sleep() early breaks your application, you're probably abusing it. Asynchronous library calls are particularly notorious for this kind of abuse. Why call the API method to wait on the results of the call when you can just sleep(100)?
Admin
Could be classic ASP where this is a viable solution.
Alternatives:
Admin
Your fingers should be sawed off so that you can never program in your entire life again, seriously. Why the f*ck do you need to keep track of the correct server time on a client's machine. I can see why the "select now()" is appropriate SQL for generating a timestamp on the server, but why oh why do you need it on the client. And if so, why not use NTP to sync a client's time if it is absolutely necessary to be in sync with the server.
Admin
TRWTF is lack of a loop to deal with >59 seconds, is it not?
Preferably in a proc:
Admin
Easy, turn it on its side and use one of the four flat edges. Done that lots of times.
Admin
to everyone saying this is not a WTF. Its a sleep function with a network call, a network call that could take n seconds to complete (if it completes). In fact the SQL server could be in another country the network delay maybe completely different in dev/qa/uat/live environments. just .... aghhh!!!!
Admin
TRWTF is your comment. If you have put your SQL server in a different country to the web server you should be fired. They should be in the same RACK.
Admin
And ☐ for Robertson heads, the only ones used by sane people (http://en.wikipedia.org/wiki/List_of_screw_drives#Robertson)
Admin
TRWTF is replacing the battery on a talking doll.
Seriously. WTF!!!
Admin
These functions coordinate with the current TickCount of the machine, which does not change when the user changes the time.
Admin
+1
Admin
I guess IHBT.
Admin
The real WTF is getting your kids a talking doll in the first place.
Admin
Admin
Vodka, orange juice and milk of magnesia: the Phillips screwdriver.
(Vodka and prune juice: the pile driver.)
Admin
Admin
Or maybe waiting 5 seconds means the same 5 seconds regardless if its 10am on the client or 3pm on the server. This code is senseless anyway.
Admin
pfft. Amateurs.