• (nodebb)

    The math in the first function isn't as terrible as it seems; in other words, the biggest change that's needed is adding a comment explaining what it's doing. It's not that bad of a way to display banner 0 from 0-10, 20-30, and 40-50 seconds of the current time, and banner 1 from 10-20, 30-40, and 50-60. Even the 2 * 10 can be slightly helpful, if there's a comment saying that it's 2 banners for 10 seconds each.

    The second function, though, is definitely a WTFy way to simply swap between 0 and 1.

    And Frist!

    Addendum 2023-01-25 07:14: I forgot to say that the business requirement for displaying the banners at those specific times is probably the bigger WTF.

  • Drak (unregistered)

    So you get a different banner every 20 seconds?

    Probably started way more generic.

  • Drak (unregistered) in reply to Drak
    • Every 10 seconds
  • Sauron (unregistered)

    This implementation is clearly lacking. They should handle the case of browserType == "old"

  • Sauron (unregistered)

    Joke aside , those hardcoded URLs hint that there's another WTF server-side: the code has to pass requests to CGI, and the banners have an id that probably is stored in some database.

    If so, then that's overkill, because stuffs like flashy ad banners are probably more of a static resource that an HTTP daemon like Nginx can serve directly from a public folder, there's probably no need to get some logic executed by PHP or whatever's behing the CGI (unless the banners are actually made of stuffs restricted to authenticated users).

    By the way, isn't CGI smelling a bit "legacy" in 2023?

  • Pabz (unregistered) in reply to Sauron

    Yes, how on earth would the Internet Explorer 6 users browse the site otherwise?!

  • (nodebb)

    If IndexOf(thisComment) < (2 -1), then writeLine("Comments are broken!");

  • (nodebb)

    Is this JavaScript server-side generated? The first explanation that comes to mind for the repeated hard-coded 2 is that it's the length of a server-side array of image + url objects.

  • (nodebb)

    Bonus WTF: pointless string callback to setTimeout forces an eval(). Static analysis either can't (easily) tell what's happening there.

  • (nodebb)

    Bonus bonus WTF: The code dynamically changes the banner itself, but not the URL behind it.

  • CodeMonkey403 (unregistered)

    Wouldn't be at all surprised to find out that the server side was generating the page using something like "modnum = @NumberOfBanners * @TimePerBanner"

  • Long Time Lurker (unregistered) in reply to CodeMonkey403
    Comment held for moderation.
  • Barry Margolin (github)

    I suspect there used to be code that set browserType dynamically, but they removed it. But they didn't bother removing the conditional. We've got lots of legacy code like that in our codebase, too.

  • mihi (unregistered)

    Also my first gut reaction that the browser type "new" and the "2" are inserted into the page server-side from some variable (from looking up avalilable banners from database and browser type from User Agent sniffing). And while it is technically possible to write something like

    modnum =${imageCount}0;

    instead of

    modnum =${imageCount} * 10;

    I guess the latter is the smaller WTF. Having a section on top of the script with all the server-generated variables would have been nicer, of course.

  • Catprog (unregistered) in reply to mihi
    Comment held for moderation.
  • markm (unregistered)
    Comment held for moderation.

Leave a comment on “Magic Math”

Log In or post as a guest

Replying to comment #:

« Return to Article