- 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
What if you want to create an array of 10 objects?
PS DocumentDotWrite has to be an adbuster-buster
Admin
That can actually be done much easier and cleaner:
There, fixed it for you.
Admin
CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(new Object[]{"Dumb"}))))))));
Admin
<joke> The real wtf is that he has to have a function for every number of parameters he wants to put into the array. He should just have one function that takes a parameter array. </joke>
Admin
At this point Peter should have summoned a +3 bat of kneecapping.
Captcha: nisl -- That which should be forshizled according to 1990's rappers.
Admin
array = CreateObjectArray(CreateObjectArray(o1,o2,o3,o4,o5,o6,o7,o8,o9),CreateObjectArray(o10));
Admin
There's nothing wrong with that function, IF you want to bottleneck all the document.write() calls, for like, say, debugging or logging.
Admin
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.
Admin
It's amazingly brillant.
Admin
Well, the guy has a point. He can't remember how to create an array, can't blame him for that part. But there are tools for that. He should have created a macro, or a code snippet in his IDE that does exactly that, without polluting the actual codebase.
Admin
I beg to differ. I think you can blame him for that. Call me old fashioned, but I rather thought that knowing the syntax of a language is an important part of learning and using that language. If it's that difficult, jot it down on a post-it and stick it on your monitor. The embarrassment of everybody else seeing it should encourage you to memorize it.
Admin
A more intelligent solution for this unintelligent problem would be:
Admin
Or maybe some kind of unit testing?
Or perhaps there is some kind of server-side sniff going on and in some cases it returns a different script with a different implementation function? (no idea what though).
Admin
A more intelligent way of posting is checking whether your solution has been presented yet...
Admin
The documentDotWrite function is used to circumvent the restrictions put in place after microsoft lost the eolas ActiveX lawsuit.
Basically, you can only embed ActiveX objects (including flash, quicktime, whatever) if the actual document.write call is called from an external js file.
It might seem crazy, but it isn't.
Dumbass.
Admin
At least he seems to understand polymorphism, and didn't opt for CreateOneObjectArray, CreateTwoObjectArray, CreateThreeObjectArray, ...
Admin
I can understand putting a method invocation in a function in general as methods don't really play well with functional programming techiques, but then again, neither do side-effects.
Admin
I like it!
Let's put in some more language features
There... now it's typed and all ;-)
Admin
Maybe I'm off base a little bit, but in the languages I'm used to (C/C++), this would create an array on the stack, which would cause all sorts of hell if you used it later.
Admin
FTFY
Admin
Understand? Or get lucky? Or perhaps someone helped him on that. Seriously, can you believe someone who can't remember the syntax to create an array would understand polymorphism?
Admin
Although you are technically correct, the more specific term for this is function or method overloading.
Admin
yeah, 'polymorphism' would be, like, "werewolf code" and stuff.
transverbero!
Admin
Admin
Bah, that's like me saying "vehicle" and you saying I should have used the word "truck". :P
Admin
the real wtf is that he didn't use generics.
Admin
Well you asked, so I'm going to say "incredibly stupid". And as for atdmt.com, they will always have pride of place on a special blocklist I like to call "block everything always until the end of time".
Admin
It's more like you saying black and me saying white. Method overloading is almost the inverse of polymorphism. Polymorphism means interchangeable methods with the same signature. Method overloading means methods with different signatures but the same name.
Admin
Admin
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.
Admin
You sir....... have just made my day.
Admin
Admin
Nobody cares.
Admin
Forgetting syntax ok... Collecting the common but easy to forget snippets, printing them out and sticking to my wall as a cheat sheet is what most people do about it. If its really bad you can put the snippets in the code as comments if you remember to clean them up later. Writing a workaround right in the code is ... not even a third choice.
Admin
Amazingly brilliant or incredibly stupid?
This will give you an array with two elements: the first element being an array with nine objects, the second one being object o10.
(At least if C# works in the same way as Java in this case).
Admin
For some reason my /etc/hosts maps atdmt.com to 0.0.0.0 on my machine :-)
Admin
Admin
TRWTF is not knowing the difference between Java and Javascript.
Admin
Hey! Don't drag me into this. I don't care about that either. Plus HurrDurr (the only thing his parents could say to name him) should read the previous posts.
Admin
It took 14 comments to mention EOLAS. Apparently, Alex is not a web developer. Neither are the first 13 commenters.
TDWTF is going to hell in a handbasket. A handbasket that's created by
Admin
Admin
Ok... you're retarded and retarded people are always wrong. FTFY
CAPTCHA: wisi - that new chemical added to pools to detect urine
Admin
Is that really a surprise to you?
Admin
Mine resolves then get immediately blocked by my Untangle box....can't possibly imagine why.
CAPTCHA: immitto....wait, what?
Admin
So the real WTF is me. I should learn the difference between "reply" and "quote" it seems.
Admin
These two posts have me hurting.
How would creating an array on the stack cause problems at all? If it's fixed size, who cares?
Actual "objects" and primitives created with the "new" keyword are stored on the heap (Java and C#). The variables that reference those objects are stored on the stack.
Even in C/C++ fixed-size arrays are created on the stack, so I'm not sure what QuestionMark is talking about.(http://www.chips.navy.mil/archives/99_apr/c++arrays.htm).
Admin
I also need to learn how to quote. My above post is in reference to this.
Admin
Those are in the (thankfully) now defunct ECMAScript 4.0 draft standard. For implementations check ActionScript 3.0 and JScript.NET. 'course, dkf was still wrong, but whatever...
Admin
Admin
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
into something like .The problem with this specific case, though, is probably that the idea of compressing the production code was kind of dropped in a hurry.