• Gore (unregistered)

    First!

    Why is there PHP in .net?

  • JHP (unregistered)

    Funny how the .NET application is all PHPey!

    **Note from Mark - Boy, am I a dummy. Ok, fixed. (I blame the uplift project I'm working on at the day job for polluting my brain on this one.)

  • Jamie (unregistered)

    Simple - there's PHP because if you want something done slow you palm it off to PHP every time !

  • Blaine (unregistered)

    That's not a hack, that's a rather clean and straightforward way to implement a requested feature.

  • Gore (unregistered)

    I´m tired of stupid php jokes.

  • wat (unregistered)

    WTF #1: Implementing a slow-down in the first place WTF #2: Implementing a loop instead of sleep() WTF #3: Implementing PHP in a supposedly .NET project

  • Seth (unregistered) in reply to Blaine

    Hahahahaha

    Troll fail

    (captcha: "decet" (quod licet Iovem, non licet bovem!?))

  • Blaine (unregistered) in reply to wat
    wat:
    WTF #2: Implementing a loop instead of sleep()

    The code is supposed to imitate hard work, sleeping just doesn't do it for you.

  • (cs)

    Unless I'm mistaken.. the ASP.NET application was crappy so the solution was, evidently, to REWRITE IT in PHP to make it less crappy.

    Now THERE'S a WTF.

    EDIT: Reading further, it sounds like the old app was ASP (Classic) and the new one was .NET, but the code sample is obviously PHP. Either my assumption above is right and it was ASP.NET rewritten to PHP, or it's an anonymization error.

  • Ryan Fox (unregistered)

    Back in the 90s, we needed speed-up loops. Now that it's the future, things happen too fast, so we need slow down loops.

    http://thedailywtf.com/Articles/The-Speedup-Loop.aspx

  • faoileag (unregistered) in reply to Ryan Fox
    Ryan Fox:
    Back in the 90s, we needed speed-up loops. Now that it's the future, things happen too fast, so we need slow down loops.
    Back in the 80s I once needed a slow-down-loop as well. I wrote a little game (think snake) in BASIC and it worked smoothly. I ran the BASIC through a compiler, and boy, was it fast! Then I rewrote the game in Z80-Assembler and I had to insert a slow-down-loop because otherwise the head of the snake would crash into the opposite wall before I could hit one of the control keys :-)

    Ah, those were the days...

  • Loop (unregistered)

    Why is this anything new or strange? For applications doing some heavy data manipulation, the process finishing too fast can make the users feel like it wasn't done properly. Some graphic representation of the know variety to go along with the fake processing time would also be a nice touch.

    Just make sure you're shortening the wait time in subsequent releases, while making a lot of noise about "algorithm improvements" and it's a win-win situation for users and developers.

  • Jay Blanc (unregistered)

    The true WTF is, and deep down we all know this, that Jones was right. Being a lot faster on saving the data would mean that a significant portion of the users would file duplicates because "the first one went through too fast so it must have failed". Programmers often forget to account for the humans.

  • faoileag (unregistered)

    Definitely only a temporary hack. Without knowing too much about PHP, that version of wait($secs) is definitely not 2038-01-19 safe!

  • Joat (unregistered)

    The real WTF with this solution is going to crop up in 10 years when all the original developers has left the company and the new hire gets tasked with improving the performance....

  • Gore (unregistered) in reply to Joat
    Joat:
    The real WTF with this solution is going to crop up in 10 years when all the original developers has left the company and the new hire gets tasked with improving the performance....

    We are here to remember it!

  • Question (unregistered)

    Does this not break if you go off the end of a minute? E.g. try to do a 5-second pause starting at xx:xx:58?

  • Ash (unregistered)

    Next step, over the course of a few months, increase the slowdown by a small amount every day, say 50ms.

  • QJo (unregistered)

    The real WTF is users being accustomed to computers being slow.

    Every time I upgrade my home PC, I get a version of Windows on it (yeah yeah, "TRWTF is Windows") which is bigger and more unwieldy, yet runs considerably slower, than the previous version. It is impossible, unless you build it yourself out of sources whose provenance may not be 100% reliable, to get hold of a new machine running the previous (perfectly adequate) version of the operating system - you can only buy that new updated version.

    I questioned the salesguy on this point once, and he shrugged and said: It's what the buyers want. What?!? How can a slower and less reliable machine be what the buyers want?!? Well, he explained, the user thinks that if the computer isn't spending lots and lots of time thinking hard and racing round and round in circles, then it's not a very good computer. If it responds practically instantaneously to commands to open the email program, open a browser on the screen, find the file you were looking for, typing a character of text into an empty email (a response time of 5 seconds is de rigueur for the latter, apparently), then "it can't be doing much".

    And I wonder whether those interminable software updates from MicroSoft deliberately include slow-down loops for machines older than 6 weeks old specifically so as to force users to upgrade when they wouldn't otherwise need to.

  • Answer (unregistered) in reply to Question
    Question:
    Does this not break if you go off the end of a minute? E.g. try to do a 5-second pause starting at xx:xx:58?
    It's comparing Unix timestamps.
  • faoileag (unregistered) in reply to Question
    Question:
    Does this not break if you go off the end of a minute? E.g. try to do a 5-second pause starting at xx:xx:58?
    Nope, the "sec" property returns the seconds since the start of the Unix epoch.
  • (cs)

    The real WTF is getting a pizza lunch as a reward. I mean, the salaries are WAAAAAAAYYY higher than the prize of a pizza. Or aren't they? It's like throwing some alms, except this raises your cholesterol. "Here you go, old chap. Well done."

  • (cs)

    I don't know php, but why not something like

            $stop=(int)(gettimeofday()["sec"]);

    instead of

            $temp=gettimeofday();
            $stop=(int)$temp["sec"];

    ?

    Unnecessary temp variables irritate me and breaking simple tasks up arbitrarily just makes everything longer and harder to follow. (Not that this is an extreme example or anything)

  • Sarten X (unregistered)

    This seems perfectly reasonable to me. Users are morons, and that must be accounted for.

    Now, of course, a proper implementation would have used sleep() rather than spinning, and for extra elegance, a descriptive comment should be included along with a simple calculation so that the delay approaches zero over the next five years. That way, even if it's never maintained, the site speeds itself up gradually, without the users worrying.

  • Chris (unregistered) in reply to QJo
    Every time I upgrade my home PC, I get a version of Windows on it (yeah yeah, "TRWTF is Windows") which is bigger and more unwieldy, yet runs considerably slower, than the previous version.

    Balls, frankly. Windows 7 is faster than Vista on the same hardware, and Windows 8 is faster than 7 (even though it's next to unusable because it mungs a touch-optimised UI into mouse interaction).

  • mharman (unregistered) in reply to dookdook
    dookdook:
    I don't know php, but why not something like
            $stop=(int)(gettimeofday()["sec"]);
    instead of
            $temp=gettimeofday();
            $stop=(int)$temp["sec"];
    ?

    Unnecessary temp variables irritate me and breaking simple tasks up arbitrarily just makes everything longer and harder to follow. (Not that this is an extreme example or anything)

    Because you couldn't access an "array" directly from a function prior to the latest version of PHP.

    http://www.php.net/manual/en/migration54.new-features.php

  • (cs)

    Why write any code at all? Just underclock the server for a few months.

  • (cs) in reply to mharman
    mharman:
    Because you couldn't access an "array" directly from a function prior to the latest version of PHP.

    http://www.php.net/manual/en/migration54.new-features.php

    Ah. Fair enough, then.

  • Pock Suppet (unregistered) in reply to dookdook
    dookdook:
    I don't know php, but why not something like
            $stop=(int)(gettimeofday()["sec"]);
    instead of
            $temp=gettimeofday();
            $stop=(int)$temp["sec"];
    ?

    Unnecessary temp variables irritate me and breaking simple tasks up arbitrarily just makes everything longer and harder to follow. (Not that this is an extreme example or anything)

    Because, until fairly recently, PHP didn't allow using getting the value of a returned array element without using an intermediate variable.

    And call it my brief and horrible experiences with functional programming, but I'll take a couple intermediate variables which break a process into several obvious steps rather than a blob of parens and commas nested six levels deep. For that matter, any logic that complex is worth considering moving into its own method/function. Writing for maintainability > writing for conciseness, with a few very narrow exceptions. You have to assume the guy reading it will be dumber than you, especially if it's going to be you-in-six-months.

  • (cs)

    I think we should do a workflow change. After the user clicks save, it pops up a dialog that says, "Click here to confirm save". No "Cancel" should be present. When they do that, then it presents another screen that shows their saved data for review, and there's a "Confirm" button on that they have to click to continue.

    Then we can have a dialog that says, "Click here to confirm confirmation..."

  • Anonymous Paranoiac (unregistered) in reply to Pock Suppet
    Pock Suppet:
    dookdook:
    Unnecessary temp variables irritate me and breaking simple tasks up arbitrarily just makes everything longer and harder to follow. (Not that this is an extreme example or anything)
    Because, until fairly recently, PHP didn't allow using getting the value of a returned array element without using an intermediate variable.

    And call it my brief and horrible experiences with functional programming, but I'll take a couple intermediate variables which break a process into several obvious steps rather than a blob of parens and commas nested six levels deep. For that matter, any logic that complex is worth considering moving into its own method/function. Writing for maintainability > writing for conciseness, with a few very narrow exceptions. You have to assume the guy reading it will be dumber than you, especially if it's going to be you-in-six-months.

    This. If I have to think, I want it to be on important things like solving new problems or pondering the problems and possibilities of time travel, not figuring out how problems that were already solved were solved.

    Granted, the example here doesn't take much thought and "$temp" is not a particularly helpful intermediate variable name, so it's not exactly a great example of writing clear code.

  • ereh-emaNrouY (unregistered) in reply to eViLegion

    Code is easier to fix and easy to ignore. For those not wishing to use the wait function, they don't have to. Unlike underclocking a server.

  • trololo (unregistered)

    /* Wait

    Makes the FRIST wait

    @access public

    • @param int the number of seconds to wait
    • @return none */
      function wait($secs) { $temp=gettimeofday(); $start=(int)$temp["sec"]; while(1) { $temp=gettimeofday(); $stop=(int)$temp["sec"]; if ($stop-$start >= $secs) break; } } echo 'FRIST';
  • ¯\(°_o)/¯ I DUNNO LOL (unregistered) in reply to eViLegion
    eViLegion:
    Why write any code at all? Just underclock the server for a few months.
    Better yet, install a Bitcoin miner and sell the Bitcoins for Friday beer bashes.

    That's certainly a lot more useful than a fucking busy-wait loop.

  • ereh-emaNrouY (unregistered) in reply to eViLegion
    eViLegion:
    Why write any code at all? Just underclock the server for a few months.
    Code is easier to fix and easy to ignore. For those not wishing to use the wait function, they don't have to. Unlike underclocking a server.

    (Now with quoting goodness.)

  • Mike (unregistered) in reply to eViLegion

    Waa waa what? php is easier than ASP? Maybe asp from the dark ages but modern MVC stuff? With one of if not the best IDE vs in all likelihood an editor from the 70's. Yeah okay, easier.

  • Jens Henrik (unregistered) in reply to faoileag

    It is not even midnight safe!

  • (cs)

    AKA a Speed-up Loop

    Why invent a new more boring name?

  • (cs) in reply to Pock Suppet
    Pock Suppet:
    And call it my brief and horrible experiences with functional programming, but I'll take a couple intermediate variables which break a process into several obvious steps rather than a blob of parens and commas nested six levels deep.

    Heh, so I'm guessing this excerpt from a personal project of mine wouldn't get me hired in any IT department you were in charge of.

    http://img401.imageshack.us/img401/2144/screenshotfrom201306040.png

    That's

    1. Reading a webpage
    2. Parsing out certain data items from the html with a regex
    3. Filtering out unacceptable items (after checking that filtering is required)
    4. Initializing a set of POD objects for each remaining item and putting them in a list for further processing.

    all in one 16-line statement. IMO judicious indentation makes it perfectly readable.

    (maybe this is why I'm unemployed xD)

  • moving through space (unregistered) in reply to Gore
    Gore:
    I´m tired of stupid php jokes.
    If stupid php would just go away, there'd be no more stupid php jokes.
  • Anonymous Paranoiac (unregistered) in reply to dookdook
    dookdook:
    Pock Suppet:
    And call it my brief and horrible experiences with functional programming, but I'll take a couple intermediate variables which break a process into several obvious steps rather than a blob of parens and commas nested six levels deep.

    Heh, so I'm guessing this excerpt from a personal project of mine wouldn't get me hired in any IT department you were in charge of.

    http://img401.imageshack.us/img401/2144/screenshotfrom201306040.png

    I get a 404.

  • PSulecki (unregistered) in reply to eViLegion
    eViLegion:
    Why write any code at all? Just underclock the server for a few months.
    But then the server wouldn't run SETI@Home as efficiently as before. On the other hand, SETI@Home could be a solution in itself :)
  • Weedo (unregistered)
    Why write any code at all? Just underclock the server for a few months.

    Or just press the Turbo button

  • (cs)

    Actually, after poking around, the biggest WTF is that they didn't use usleep(). Why burden the CPU with a delay loop when you can just pause the program?

  • 3rd Ferguson (unregistered) in reply to eViLegion

    Because infrastructure should be invisible. Once you've started down the path of making both hardware AND software changes in order to tweak the user experience, you've introduced a whole other world to your troubleshooting process in the event anything starts behaving unexpectedly. Best practice is to over-test your hardware when you install it and then lock the rack and leave it alone for as long as you possibly can. Whenever possible, decouple hardware functions from one another, again to eliminate components from any troubleshooting procedures. That is why there are SANs, tape robots and network switches even though your server can physically hold ten hard drives, its own tape drive and a deck of NICs.

    /maybe the OP was being sarcastic but I've seen it for real too many times

  • (cs)

    I must to confess to having been forced to do something similar, however we put in certain protections:

    1. The delay was set to scale down based on the version number; every release would contain "performance enhancements" without any need for developer intervention. This way, if everybody forgot about it, we wouldn't be tanking performance a year from now.

    2. A scheduled task was added to email the ceo, cto, and developer distribution list the total amount of time lost to this delay in a quarterly report. This amount was expressed in terms of time and the amount of money to employ people for that length of time.

  • wat (unregistered)

    http://php.net/manual/pl/function.sleep.php

  • (cs) in reply to Anonymous Paranoiac
    Anonymous Paranoiac:
    I get a 404.

    Weird. How about this?

    http://tinypic.com/r/2rclo5c/5

    (Come on, just post. This isn't spam.....)

  • Chelloveck (unregistered) in reply to Kaosadvokit
    Kaosadvokit:
    2) A scheduled task was added to email the ceo, cto, and developer distribution list the total amount of time lost to this delay in a quarterly report. This amount was expressed in terms of time and the amount of money to employ people for that length of time.

    You are obviously not a team player and are an all-around mean and vindictive person. I like that!

  • Damadar (unregistered) in reply to eViLegion

    Probably because that is taking a hammer to a problem that required a screwdriver.

    Code's easier to work with than re-clocking the CPU; can be done dynamically without fear, and doesn't affect any other programs that might be running on the server.

Leave a comment on “The Slow Down Loop”

Log In or post as a guest

Replying to comment #:

« Return to Article