• LCrawford (unregistered)

    This was their frist attempt to simulate the functionality of window.onload() or $( document ).ready() , since they hadn't gotten to that part of the HTML documentation. It leaves quite a bit to be desired however.

  • (nodebb)

    Actually, it's really good that setTimeout cannot throw a typeError, because if it does, there would be an immediate infinite recursion, at least until it throws an exception because of exploding the call stack or running out of memory.

  • (nodebb)

    Current status: mapping not available, the developers are lost in the wilderness.

  • Robin (unregistered)

    This is without doubt some of the most eye-watering-ly bad Javascript code I've ever seen - for all the reasons spelled out in the article.

    However, TRWTF is surely what this code actually does, or doesn't, or perhaps is meant to, do. What effect does any of this have on any observable outcomes? It appears to want to continually reset some global variables to particular values, every 2 seconds - and if that really is needed, and if someone thought this was the right solution to whatever the problem is (hey maybe consider not using globals if you're worried about random things overwriting the values unpredictability?), then there's a whole other WTF story waiting to be told here.

    Although I don't think this code would even do that properly, the eval-ed string passed to setTimeout is read in global scope (I think) so this just sets those global values to whatever values they already have.

    I have to ask - I do write JS for a living but am not familiar with the screwed up dialect used here - am I missing something that makes this code actually do anything?

  • Edd (unregistered)

    Bet the two second delay is because it does throw exceptions and they don't want it to break the stack right away.

  • Duston (unregistered)

    "gods forbid that we pass parameters." I'm old school, so when I ran into the OOP paradigm where you set properties on an object and then call the (parameterless) method, to me that felt the same or similar to using global variables. It felt...wrong. But maybe that's what they're trying to (WTFly) emulate here? So you can test the method with "WTF dependency injection?"

  • Splatmandeux (unregistered)

    The 2 second delay reminded me of a war story: In a previous life I worked on a project that was a hand-held gaming device for folks waiting on a restaurant seat that would let them play games, feed them advertisements and page them when a table was ready. It used wifi to fetch new media and send statistics to a server every so often. We're talking like 100+ devices for a given AP. Suffice it to say it performed poorly on the 802.11g era consumer routers. Occasionally there would be delays getting to the server. The pointy-haired bosses most excellent suggestion was that when connectivity to the server was deemed lost, we would switch to a mode where we'd try to reconnect to it every 1/2 second. The strategy was to 'bully' the server into responding to us, not getting that would make the problem worse. We said "sure", and then promptly didn't implement it. Smart phones eventually made the product pointless anyway. (This was deployed around the time of the first iPhone) I've seen many mystery timeouts over the years, and I always shudder.

  • Angela Anuszewski (google) in reply to Splatmandeux

    Hey, if it is the one I am thinking of.... I loved that thing's version of Monopoly that I can't seem to find on any other device.

  • (nodebb) in reply to Duston

    Are you thinking of builder patterns? Those make sense for e.g. a SQL builder, where you can call the setters in any order (and e.g. optionally based on business logic) and then when you call "get" it assembles a correct SQL query and runs it. Something like that?

    This... doesn't resemble that...

  • Brian Boorman (google) in reply to Angela Anuszewski

    I think it also had the option to listen to the Lonsberry podcast.

  • (nodebb) in reply to konnichimade

    It sounds more like the two-stage initialization anti-pattern. The object is constructed, but isn't ready to use until some extra setup is done (e.g., calling an init() method, setting properties directly, etc.).

    Builder pattern is a way to avoid this anti-pattern. You don't get an unusable, half-constructed object. Instead, you first create a fully usable builder object. Once you're done building, then you call get() (or build() or whatever), and you have a fully usable object of the class you actually want.

  • Foo AKA Fooo (unregistered) in reply to Angela Anuszewski

    Hold on, they played Monopoly while waiting to be seated? Why not Civilization or The Campaign For North Africa?

  • Sole Purpose Of Visit (unregistered) in reply to Duston

    Nothing wrong with that. Except.

    The compiler has no way of verifying your parameters. Neither does the jitter. Neither one will optimise performance, either.

    You're relying on either type-casting (since, in general, property bags are passed as a collection of objects).

    You're probably relying on stringified types (the property key being a string, and the property value being an object).

    But as I say, nothing wrong with that. I love dealing with this stuff. I love the fact that I have to deal with this stuff every friggin day. Though it's certainly less painful than having to deal with what appears to be an endless set of abject javascript moronisms.

  • (nodebb) in reply to Duston

    From what I've seen, mutable objects can easily become hidden globals for most purposes. They can create a weird coupling across subroutines, that veryich mimicks the issues of mutable global state, though at least now you can maintain multiple copies.

    I am seeing this issue heavily in Fortran, very everything by default is passed by reference. After "call do_stuff(i)", you cannot be sure if I has changed, even if it is an integer - except by reading the code of do_stuff.

    Only, where in other languages "addItemsTo(list)" might be an antipater, Fortran doesn't give you better tools.

    Mind you, Fortran is great for numerical algorithms and parallelization thereof. Sadly it sucks at the whole "get the data to the algorithm" part.

  • NoLand (unregistered)

    How old this piece of code? It looks much like the kind of code you would encounter in the mid-1990s, when JS was often poorly understood by those who implemented it.

    Fun fact: Back then, global resources became available, as the browser parsed certain tags. E.g., the document object became available, as the the body tag was encountered, an entry to document.images was added, as the respective image tag was parsed, etc. MS IE 4 added a special variety to this: Namely, its special document.all collection became available only after a short delay after the body was entirely parsed and this delay depended on various things, like the system language. E.g., the delay was typically shorter than 0.4s on a German NT system, but about double this on an English NT system running IE with the same built number. The 2000ms delay looks much like," let's make it double the timeout to be on the safe side, since we do not know, what might be out there."

  • Nel (unregistered) in reply to Steve_The_Cynic

    If I had to guess I'd say they didn't have the setTimeout at first and they ran into this problem, so they used the setTimeout to "fix" it.

  • Anonymouse (unregistered)

    This code is crazier than it looks.

    The performAdd method schedules a call to addMapService. When this call happens, it passes in the current global map type and URL and proceeds to set those same values back into the same globals. After the globals are set to the same value that they already held, performAdd is called again.

    In other words, this code is performing a no-op method call every 2 seconds... because reasons.

  • Craig (unregistered) in reply to R3D3

    Any Fortran code newer than 30 years old should be using INTENT on the arguments, so you wouldn't need to read the entire routine to see if i might change, only the interface. That would put it on par with several other languages, including VB and C++ (though not C, nor C# in the case where i is a value type).

Leave a comment on “Without a Map, Without a Clue”

Log In or post as a guest

Replying to comment #:

« Return to Article