• SR (unregistered)

    What if you want to create an array of 10 objects?

    PS DocumentDotWrite has to be an adbuster-buster

  • (cs)

    That can actually be done much easier and cleaner:

    public static object[] CreateObjectArray(object ... o)
    {
        return o;
    }

    There, fixed it for you.

  • frits (unregistered)

    CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(CreateObjectArray(new Object[]{"Dumb"}))))))));

  • (cs)

    <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>

  • highphilosopher (unregistered)

    At this point Peter should have summoned a +3 bat of kneecapping.

    Captcha: nisl -- That which should be forshizled according to 1990's rappers.

  • AndrewB (unregistered) in reply to SR

    array = CreateObjectArray(CreateObjectArray(o1,o2,o3,o4,o5,o6,o7,o8,o9),CreateObjectArray(o10));

  • 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.

  • Anthony (unregistered) in reply to gus

    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.

  • Paula (unregistered)

    It's amazingly brillant.

  • (cs)

    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.

  • Anon (unregistered) in reply to Kiss me I'm Polish
    Kiss me I'm Polish:
    Well, the guy has a point. He can't remember how to create an array, can't blame him for that part.

    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.

  • Robert (unregistered)

    A more intelligent solution for this unintelligent problem would be:

    public static object[] CreateObjectArray(params object[] o) { return o; }
  • Graham Stewart (unregistered) in reply to gus
    gus:
    There's nothing wrong with that function, IF you want to bottleneck all the document.write() calls, for like, say, debugging or logging.

    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).

  • Steenbergh (unregistered) in reply to Robert
    Robert:
    A more intelligent solution for this unintelligent problem would be:
    public static object[] CreateObjectArray(params object[] o) { return o; }

    A more intelligent way of posting is checking whether your solution has been presented yet...

  • (cs)

    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.

  • Neville Flynn (unregistered)

    At least he seems to understand polymorphism, and didn't opt for CreateOneObjectArray, CreateTwoObjectArray, CreateThreeObjectArray, ...

  • Your Name (unregistered)

    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.

  • den Ben (unregistered) in reply to Robert
    Robert:
    A more intelligent solution for this unintelligent problem would be:
    public static object[] CreateObjectArray(params object[] o) { return o; }

    I like it!

    Let's put in some more language features

    public static T[] CreateObjectArray<T>(params T[] o) { return o; }

    There... now it's typed and all ;-)

  • QuestionMark (unregistered)
    Severity One:
    That can actually be done much easier and cleaner:
    public static object[] CreateObjectArray(object ... o)
    {
        return o;
    }

    There, fixed it for you.

    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.

  • frits (unregistered) in reply to Neville Flynn
    Neville Flynn:
    At least he seems to understand method overloading, and didn't opt for CreateOneObjectArray, CreateTwoObjectArray, CreateThreeObjectArray, ...

    FTFY

  • Anthony (unregistered) in reply to Neville Flynn
    Neville Flynn:
    At least he seems to understand polymorphism, and didn't opt for CreateOneObjectArray, CreateTwoObjectArray, CreateThreeObjectArray, ...

    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?

  • Anonymous Coward (unregistered) in reply to Neville Flynn

    Although you are technically correct, the more specific term for this is function or method overloading.

  • Thg (unregistered) in reply to Anonymous Coward
    Anonymous Coward:
    Although you are technically correct, the more specific term for this is function or method overloading.

    yeah, 'polymorphism' would be, like, "werewolf code" and stuff.

    transverbero!

  • (cs) in reply to QuestionMark
    QuestionMark:
    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.
    But this is Javascript, which doesn't partition the world into “values on the stack” and “values in the heap”. (Implementations might, but they'll also insert such copies as necessary.) Sure, this does cost a bit of performance, but it makes programmers' lives much simpler.
  • Neville Flynn (unregistered) in reply to frits
    frits:
    Neville Flynn:
    At least he seems to understand method overloading, and didn't opt for CreateOneObjectArray, CreateTwoObjectArray, CreateThreeObjectArray, ...

    FTFY

    Bah, that's like me saying "vehicle" and you saying I should have used the word "truck". :P

  • tim (unregistered)

    the real wtf is that he didn't use generics.

  • Anonymous (unregistered)

    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".

  • frits (unregistered) in reply to Neville Flynn

    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.

  • Anonymous (unregistered) in reply to evrt
    evrt:
    The documentDotWrite function is used to circumvent the restrictions put in place after microsoft lost the eolas ActiveX lawsuit.
    OK, that sounds reasonable.
    evrt:
    Basically, you can only embed ActiveX objects (including flash, quicktime, whatever) if the actual document.write call is called from an external js file.
    Really, how interesting.
    evrt:
    It might seem crazy, but it isn't.
    Gee, I guess you're right.
    evrt:
    Dumbass.
    WTF? Where the hell did that come from? I thought we were friends?
  • 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.

  • //Rumen (unregistered) in reply to highphilosopher
    highphilosopher:
    At this point Peter should have summoned a +3 bat of kneecapping.

    Captcha: nisl -- That which should be forshizled according to 1990's rappers.

    You sir....... have just made my day.

  • (cs) in reply to dkf
    dkf:
    But this is Javascript, which doesn't partition the world into “values on the stack” and “values in the heap”.
    Oh really? Where's this version of Javascript that supports the "public" and "static" keywords?
  • asdflp (unregistered) in reply to HurrDurr
    HurrDurr:
    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.

    Nobody cares.

  • Death (unregistered)

    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.

  • Jasper (unregistered) in reply to AndrewB
    AndrewB:
    array = CreateObjectArray(CreateObjectArray(o1,o2,o3,o4,o5,o6,o7,o8,o9),CreateObjectArray(o10));

    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).

  • pseudocode (unregistered)

    For some reason my /etc/hosts maps atdmt.com to 0.0.0.0 on my machine :-)

  • Anonymous (unregistered) in reply to HurrDurr
    HurrDurr:
    I'm 90% sure I know what's behind DocumentDotWrite... <Snipped dupe post>

    Prove me wrong.

    Read the damn comments, this has already been posted. Prove me wrong.

  • therealwtf (unregistered) in reply to dkf

    TRWTF is not knowing the difference between Java and Javascript.

  • Nobody (unregistered) in reply to asdflp
    asdflp:
    HurrDurr:
    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.

    Nobody cares.

    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.

  • (cs)

    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

    public static handbasket(user0, user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12, user13) {
      return new object[] {user0, user1, user2, user3, user4, user5, user6, user7, user8, user9, user10, user11, user12, user13};
    }
  • Quirkafleeg (unregistered) in reply to pseudocode
    pseudocode:
    For some reason my /etc/hosts maps atdmt.com to 0.0.0.0 on my machine :-)
    And 192.0.2.1 here. I can't think why.
  • HeebyJeeby (unregistered) in reply to HurrDurr
    HurrDurr:
    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.

    Ok... you're retarded and retarded people are always wrong. FTFY

    CAPTCHA: wisi - that new chemical added to pools to detect urine

  • (cs) in reply to phihag
    phihag:
    It took 14 comments to mention EOLAS. Apparently, Alex is not a web developer. Neither are the first 13 commenters.

    Is that really a surprise to you?

  • me (unregistered) in reply to Quirkafleeg

    Mine resolves then get immediately blocked by my Untangle box....can't possibly imagine why.

    CAPTCHA: immitto....wait, what?

  • me (unregistered) in reply to Quirkafleeg
    Quirkafleeg:
    pseudocode:
    For some reason my /etc/hosts maps atdmt.com to 0.0.0.0 on my machine :-)
    And 192.0.2.1 here. I can't think why.

    So the real WTF is me. I should learn the difference between "reply" and "quote" it seems.

  • Jon (unregistered) in reply to dkf

    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).

  • Jon (unregistered) in reply to QuestionMark
    QuestionMark:

    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.

    I also need to learn how to quote. My above post is in reference to this.

  • zoips (unregistered) in reply to Zylon
    Zylon:
    dkf:
    But this is Javascript, which doesn't partition the world into “values on the stack” and “values in the heap”.
    Oh really? Where's this version of Javascript that supports the "public" and "static" keywords?

    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...

  • Pffft! (unregistered) in reply to Jon
    Jon:
    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).

    The problems come when you (try to) use it later. What happens when a function returns an array on the stack?

  • 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.

Leave a comment on “Amazingly Brilliant or Incredibly Stupid”

Log In or post as a guest

Replying to comment #:

« Return to Article