- 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
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.
Admin
Actually, it's really good that
setTimeout
cannot throw atypeError
, 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.Admin
Current status: mapping not available, the developers are lost in the wilderness.
Admin
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?
Admin
Bet the two second delay is because it does throw exceptions and they don't want it to break the stack right away.
Admin
"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?"
Admin
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.
Admin
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.
Admin
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...
Admin
I think it also had the option to listen to the Lonsberry podcast.
Admin
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.
Admin
Hold on, they played Monopoly while waiting to be seated? Why not Civilization or The Campaign For North Africa?
Admin
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.
Admin
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.
Admin
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."
Admin
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.
Admin
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.
Admin
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).