• (cs)

    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.

  • Captain Boolean (unregistered)

    Innovate method of overcoming max interval on timers of ~65secs, no, wait...

  • (cs)

    Well, it works, right? And don't we keep hearing the old saying "Never change a running system."?!?

  • (cs)

    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.

  • R (unregistered)

    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.

  • Arete (unregistered)

    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?

  • Sehe (unregistered)

    she didn't know that he had tools available to add a delay to some process

    Well, she clearly had the right tools available to add a delay to the process!

    The development process, that is

  • Accalia.de.Elementia (unregistered) in reply to R
    R:
    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.

    that's easy. I'd just need one or two extra ingredients. like some bondo, superglue, or a tig welder.

  • (cs)

    Wow, I never realized it was even possible to create a sleep function that is susceptible to sql inject.

  • (cs)

    It's not totally a WTF to use the database to implement sleeps for the following reasons:

    1. 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.

    2. 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.

    3. We'll be able to store in the database an accurate log of all the sleeps.

    4. 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...

  • (cs)

    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?

  • (cs) in reply to TheRider
    TheRider:
    Well, it works, right? And don't we keep hearing the old saying "Never change a running system."?!?
    I thought it was: "never run a changing system".
  • (cs) in reply to Cbuttius
    Cbuttius:
    It's not totally a WTF to use the database to implement sleeps for the following reasons:
    1. 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.

    2. 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.

    3. We'll be able to store in the database an accurate log of all the sleeps.

    4. 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...

    Show me any example, and I'll show you a better way of going about it. This is a waste both on the SQL end and the webserver.
  • (cs) in reply to Anketam
    Anketam:
    Wow, I never realized it was even possible to create a sleep function that is susceptible to sql inject.
    probebly healthier to forget you ever saw that code.
  • haero (unregistered)

    Meh. Sleep() is overrated.

  • asdf (unregistered)

    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.

  • (cs) in reply to asdf
    asdf:
    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.
    Why on Earth would you rely on wall clock time rather than system clock time from a fixed epoch?
  • (cs) in reply to asdf

    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)

  • (cs) in reply to Vanders
    Vanders:
    asdf:
    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.
    Why on Earth would you rely on wall clock time rather than system clock time from a fixed epoch?
    Very simple: because your user might move his computer at a speed close to that of light, and therefore slow time down when compared to the server. Don't you know anything about physics?

    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.

  • Wim (unregistered) in reply to asdf
    asdf:
    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.
    And another thing is, that this code is independent of the system where it runs. Calling an OS Sleep function is machine specific, server code not. I like the SELECT SYSDATE FROM DUAL approach (ok, I'm an Oracle user).
  • (cs)

    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.

  • (cs)

    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).

  • (cs) in reply to Severity One
    Severity One:
    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.

    Actually, that is something that I can get behind.

    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.

  • (cs) in reply to Some Jerk
    Some Jerk:
    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?
    Doesn't matter, it's still a Darwin Award!
  • Ben (unregistered)

    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.

  • (cs) in reply to R
    R:
    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.

    Thats what a dremel is for. Make your cross-slot and you are golden. Thats what it looks like he did here, modify the project to accomidate his tool.

  • Nagesh (unregistered)

    Jest petal to storing. In India, you are be getting them for less than 1200 rupees.

  • Swedish tard (unregistered) in reply to R
    R:
    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.

    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...

  • SteveThePirate (unregistered) in reply to asdf
    asdf:
    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.
    I don't understand. The VB code is executing on the server. The user changing their machine's time would do nothing. Why doesn't DateTime.Now not work?
  • mozzis (unregistered) in reply to R

    I've done that. You have to use just one of the flanges of the crosspoint.

  • Ben Jammin (unregistered) in reply to Swedish tard
    Swedish tard:
    R:
    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.

    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...

    • = flat head
    • = phillips
  • Ben Jammin (unregistered) in reply to Ben Jammin
    Ben Jammin:
    Swedish tard:
    R:
    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.

    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...

    • = flat head
    • = phillips
    IHBT
  • (cs) in reply to asdf
    asdf:
    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.

    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)?

  • Simon (unregistered)

    Could be classic ASP where this is a viable solution.

    Alternatives:

    1. Busy-wait (increase server load)
    2. Install & pay for a 3rd party control
  • blah (unregistered) in reply to asdf
    asdf:
    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.

    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.

  • Dave (unregistered)

    TRWTF is lack of a loop to deal with >59 seconds, is it not?

    Preferably in a proc:

    CREATE PROCEDURE [Sleeper]
    @sleep int	-- Sleep time in Seconds
    AS
    WHILE @sleep >59 BEGIN
    WAITFOR DELAY '00:01:00';
    SET @sleep -= 60;
    END;
    DECLARE @delay nvarchar(8) = '00:00:' + CONVERT(nvarchar(2), @sleep);
    WAITFOR DELAY @delay;
    GO

  • TrogL (unregistered) in reply to R

    Easy, turn it on its side and use one of the four flat edges. Done that lots of times.

  • dr memals (unregistered)

    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!!!!

  • Ben (unregistered) in reply to dr memals

    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.

  • (cs) in reply to Ben Jammin
    Ben Jammin:
    - = flat head + = phillips

    And ☐ for Robertson heads, the only ones used by sane people (http://en.wikipedia.org/wiki/List_of_screw_drives#Robertson)

  • satoshi (unregistered)

    TRWTF is replacing the battery on a talking doll.

    Seriously. WTF!!!

  • (cs) in reply to asdf
    asdf:
    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.

    These functions coordinate with the current TickCount of the machine, which does not change when the user changes the time.

  • (cs) in reply to satoshi
    satoshi:
    TRWTF is *replacing* the battery on a talking doll.

    Seriously. WTF!!!

    +1

  • foo (unregistered) in reply to Wim
    Wim:
    asdf:
    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.
    And another thing is, that this code is independent of the system where it runs. Calling an OS Sleep function is machine specific, server code not.
    You mean this code runs on all OSs that VB runs on? Wow!

    I guess IHBT.

  • (cs)

    The real WTF is getting your kids a talking doll in the first place.

  • (cs) in reply to asdf
    asdf:
    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.
    TRWTF is an OS that doesn't provide monotonic time APIs for elapsed time measurement, or a developer who doesn't know about them. Either one, yeah.
  • (cs) in reply to gramie
    gramie:
    Ben Jammin:
    - = flat head + = phillips

    And ☐ for Robertson heads, the only ones used by sane people (http://en.wikipedia.org/wiki/List_of_screw_drives#Robertson)

    Vodka, orange juice and milk of magnesia: the Phillips screwdriver.

    (Vodka and prune juice: the pile driver.)

  • (cs) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    Some Jerk:
    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?
    Doesn't matter, it's still a Darwin Award!
    It looks like you're trying to kill yourself. Would you like help?
  • Pablo Lerner (unregistered) in reply to asdf

    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.

  • some jerk (unregistered)

    pfft. Amateurs.

        Function DelayProcess(nSeconds)
            Dim WshShell
            Set WshShell = WScript.CreateObject("WScript.Shell")
            WshShell.Run "PING 1.1.1.1 -n 1 -w " & (nSeconds * 10000) & " >NUL"
            Set WshShell = Nothing
        End Function
    
    

Leave a comment on “Square Peg Meets Round Hole”

Log In or post as a guest

Replying to comment #:

« Return to Article