| « Successed! | Classic WTF: Lacking Knowledge Essentials » |
When it comes to clever coding, there’s a fine line between amazingly brilliant and incredibly stupid. Take DocumentDotWrite.js, for example. It's a single-line JavaScript file that’s served (http://rmd.atdmt.com/tl/DocumentDotWrite.js) seemingly all the time by Microsoft’s Atlas advertising platform.
function DocumentDotWrite(s){document.write(s);}
I want to believe that there’ some Ninja JavaScript-fu going on here that my feeble mind cannot possible understand. The Daily WTF's own forums, which seems to be the only place on the ‘net where this code has been discussed, conclude that it’s a callback function for a poor man’s bind()… or some sort of ad-block/filter busting code… or even a “coding by phone” that was taken a bit too literally.
I guess we’ll never know. Like so many instances clever coding, until we hear from the actual developer behind DocumentDotWrite.js, we can only guess as to whether it’s a complete WTF or an amazing hack.
Peter, on the other hand, didn’t have to guess. When he saw a a bit of seemingly clever code, he was fortunte to have the original developer — and team lead — in the cubicle next to his. This was the code he had uncovered.
public static object[] CreateObjectArray(object o1)
{
return new object[] { o1 };
}
public static object[] CreateObjectArray(object o1, object o2)
{
return new object[] { o1, o2 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3)
{
return new object[] { o1, o2, o3 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3, object o4)
{
return new object[] { o1, o2, o3, o4 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3, object o4, object o5)
{
return new object[] { o1, o2, o3, o4, o5 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3, object o4, object o5, object o6)
{
return new object[] { o1, o2, o3, o4, o5, o6 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3, object o4, object o5, object o6, object o7)
{
return new object[] { o1, o2, o3, o4, o5, o6, o7 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3, object o4, object o5, object o6, object o7,
object o8)
{
return new object[] { o1, o2, o3, o4, o5, o6, o7, o8 };
}
public static object[] CreateObjectArray(object o1, object o2,
object o3, object o4, object o5, object o6, object o7,
object o8, object o9)
{
return new object[] { o1, o2, o3, o4, o5, o6, o7, o8, o9 };
}
“Oh that,” Peter’s coworker explained, “I sometimes forget the syntax for creating an array. You know, between the ‘new’, the square brackets, the commas, the semicolon… it can get a bit confusing. I figured this was just easier.”
At least Peter had his answer.
Re: Amazingly Brilliant or Incredibly Stupid
2009-12-14 09:17
•
by
gus
(unregistered)
|
|
There's nothing wrong with that function, IF you want to bottleneck all the document.write() calls, for like, say, debugging or logging.
|
Re: Amazingly Brilliant or Incredibly Stupid
2009-12-14 09:22
•
by
Anthony
(unregistered)
|
|
Or you had multiple child windows (either frames, iframes or JS popups), and wanted a quick and easy shortcut to write on one of the documents. Then instead of worrying about how to find the primary doc, you just simply call documentDotWrite(s) from anywhere (and document with permissions)... I'm not saying it's neat. I'm not saying it's "good". Just another possible explanation.
|
Re: Amazingly Brilliant or Incredibly Stupid
2009-12-14 10:22
•
by
HurrDurr
(unregistered)
|
|
I'm 90% sure I know what's behind DocumentDotWrite. A couple years ago there was a lawsuit that MS lost about embedding objects in a webpage. http://en.wikipedia.org/wiki/Eolas
This is exactly the workaround they suggested before they either bought the patent or killed the people behind the nonsense. Notice on the wiki page the "workaround" which is to use javascript to write the object to the DOM instead of embedding it. Prove me wrong. |
Re: Amazingly Brilliant or Incredibly Stupid
2009-12-14 13:34
•
by
Vlad Patryshev
(unregistered)
|
|
DocumentDotWrite.js by itself would be stupid; but if you use it in building and compressing your JavaScript app, it helps a lot. I mean, if you do not have automated aliasing. Google's JavaCompiler now has automated aliasing, and there's no need to have this kind of functions; but before that it made tons of sense - transforming your ubiquitous
document.write("...") into something like Qm("...").
The problem with this specific case, though, is probably that the idea of compressing the production code was kind of dropped in a hurry. |
| « Successed! | Classic WTF: Lacking Knowledge Essentials » |