• Praer (unregistered)

    AAAAHHH!!!

    It's college all over again!

  • (cs)

    This may not be as WTF as it looks. .contains and .indexOf are not part of JavaScript and are likely functions that were added on by a library. This test is doing some sanity checks on them.

    The test MAY be a bit too thorough, though.

    Addendum (2010-07-21 09:26): [Edit: Looks like .indexOf is defined in Chrome, but neither is defined in IE.]

  • Drew (unregistered)

    We need to create the Academy for the Advancement of Amazing Code (AAAC) so we can give this an Academy award for most useful code ever.

    Captcha: ideo. When your idea is so bad, it can't even be called an idea anymore.

  • Candy (unregistered)

    I'm guessing they're implementing a javascript compiler or interpreter, in which case this is completely not a wtf.

    Context missing error.

  • getofmymetriclawn (unregistered)
    if (a.contains("frist"))
        {
            printf("failed test: string found, but should not be")
            return false
        }
    

    Sorry, was trying to say something more insightful or witty, but that WTF simply left me speechless.

    And the spamfilter. That also left me speechless. Like, really speechless. Stupid spam filter! Well, I try to keep adding random stuipd sentences untile the stupid akismet let me comment. Hum. Lorem ipsum dolor? Pretty please let me post?

  • (cs)

    "Jason, the test is failing!"

    "Uh oh. Okay, seems to be a bug. Go tell the company that created Javascript and they should get right on it. We'll have a fix out to our users in no time!"

    What a useful unit test!

  • Chris (unregistered)

    TRWTF is getofmymetriclawn's comment.

    Captcha: abico, who gives a crap?

  • (cs) in reply to toth

    "Go tell the company that created Javascript and they should get right on it."

    Except JavaScript does not define .contains or .indexOf

    Thanks for playing, please try again later.

    [Edit: Chrome defines .indexOf but not .contains. Internet Explorer does not define either. Lowest Common Denominator wins, unfortunately.]

    Addendum (2010-07-21 09:27): [Edit: Err, Greatest Common Denominator.]

  • The Nerve (unregistered) in reply to Candy
    Candy:
    I'm guessing they're implementing a javascript compiler or interpreter, in which case this is completely *not* a wtf.

    Context missing error.

    Javascript itself is a wtf. A Javascript compiler is a BIG WTF.

    A place that I worked started requiring people to write unit tests for all code checked in (somebody suggested this to the CEO as a way to save their job). Time went on and the app was just as unstable as before the unit tests. It's very difficult to have reasonable unit tests without solid requirements. Not to mention that the developers did what I think I saw on another article here, writing tests like if (false != false) throw new Exception();

  • Anonymous (unregistered)

    I wish I could properly express the sound of my head hitting the desk but you'll just have to make do with the mental image. This is depressingly retarded.

  • Jay C (unregistered)

    Hmmm...

        if (a.contains(new Object()))
        {
            alert("failed test: object found, but should not be")
            return false
        }
    
    

    Make a NEW object and see if it's already in the list. That's just funny.

    And the spam filter sucks.

  • (cs)

    No Unicorns or Pink Ponies today :-(

  • Cidolfas (unregistered)

    Yeah, this is completely not a WTF. Neither indexOf nor contains are JavaScript functions. That's actually quite an exhaustive unit test, with the exception of the one misspelling.

  • John Lennon's Ghost (unregistered)

    You say goodbye, and I say hello! Hello, Hello!

  • elio (unregistered)

    oh.. yes, yes.. this one it's a really big problem. You always have to deal with this holes in arrays, you put something in them and after a while: where the hell has gone my data??

  • SeySayux (unregistered) in reply to Jay C
    Jay C:
    Hmmm...
        if (a.contains(new Object()))
        {
            alert("failed test: object found, but should not be")
            return false
        }
    

    Make a NEW object and see if it's already in the list. That's just funny.

    And the spam filter sucks.

    Actually, that seems logical to me. He/she creates a new object and checks if it's not in the list. contains() should return true if and only if there existan element X is in the array, such that the object Y passed to contains() has the property that X == Y. Or at least, that's how I learned it. So, if for none of the elements X in the array holds that X == Y, in other words, the element X is not in the array, contains(Y) has to return false. That's what's tested here.

    Anyways, I'm back to writing unit tests for (C++) containers.

  • xxx (unregistered) in reply to The Nerve
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?

  • Beavis8 (unregistered) in reply to xxx
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain?

    Javascript interpreters?

  • The Nerve (unregistered) in reply to xxx
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?

    Seriously? Ok, maybe they don't teach this in college anymore.

    A compiler takes code written in a computer language and converts it into machine code. JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions. I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX. The only use for a JavaScript compiler would be so you could write standalone programs that ran faster. If you think the Javascript language has any merits that warrant you creating standalone applications using the language, then check into the psych ward at your local mental hospital. I would rather write lolcode.

  • me (unregistered) in reply to The Nerve
    The Nerve:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?

    Seriously? Ok, maybe they don't teach this in college anymore.

    A compiler takes code written in a computer language and converts it into machine code. JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions. I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX. The only use for a JavaScript compiler would be so you could write standalone programs that ran faster. If you think the Javascript language has any merits that warrant you creating standalone applications using the language, then check into the psych ward at your local mental hospital. I would rather write lolcode.

    You should check out the games that come as default with recent Ubuntu desktop installations. At least one is written in JavaScript.

  • shadowphiar (unregistered) in reply to The Nerve

    A Just-In-Time compiler is still an compiler. I agree that JavaScript is not an ideal language, and has several misfeatures which make it difficult to compile efficiently. But the fact remains that today's browsers all contain JIT compilers, and JavaScript is no longer primarily an interpreted language.

  • AC (unregistered)

    so TRWTF is Alex not knowing Javascript.

  • (cs) in reply to The Nerve
    The Nerve:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.
    And what do you think modern browsers contain? You know, the thingie you use to *run* JavaScript code? Hello?
    Seriously? Ok, maybe they don't teach this in college anymore.
    Or perhaps someone needs to go back to college
    The Nerve:
    A compiler takes code written in a computer language and converts it into machine code.
    Or quite possibly into an intermediate, or byte, code. That's a pretty ancient technology, which goes back to the late 70s in the case of UCSD Pascal and p-code.
    The Nerve:
    JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions.
    The language name may indicate how it was first implemented. So what?
    The Nerve:
    I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX.
    Oh my. No, what you do is to compile it to a bytecode, which then has a per-platform interpreter (or JIT if really required). Why use it? Because a lot of web browsers spend a lot of time executing JavaScript, and if you can speed it up, so much the better.

    You're also making the assumption that the compilation isn't done on the very same platform that the code will execute. For something like, oh, I dunno, Google Maps, it's quite likely that the JS arrives in source form, but that your browser will compile it as soon as it requires executing, and will then carry on using that compiled code till your session ends.

  • The Nerve (unregistered) in reply to shadowphiar
    shadowphiar:
    A Just-In-Time compiler is still an compiler. I agree that JavaScript is not an ideal language, and has several misfeatures which make it difficult to compile efficiently. But the fact remains that today's browsers all contain JIT compilers, and JavaScript is no longer primarily an interpreted language.

    I had no idea! Unfortunately a theoretical WTF has become a genuine WTF.

    Are we ever going to upgrade the freaking internets?

  • john (unregistered) in reply to The Nerve

    Err...ActionScript?

  • Don (unregistered)

    I love how he inserts "goodbye" but then checks for "byebye". Great protection in case the Array class develops the ability to convert items to their casual equivalents.

  • Frz (unregistered)

    Adding to the compiler discussion: http://code.google.com/intl/de/closure/compiler/ the google closure compiler is classified as a javascript compiler as it compiles javascript (duh)

  • justsomedude (unregistered) in reply to Don
    Don:
    I love how he inserts "goodbye" but then checks for "byebye". Great protection in case the Array class develops the ability to convert items to their casual equivalents.

    java.casualLogic, brilliant!

  • Matt (unregistered)

    Mmmh... He forgot to have a "return true;" at the end of the function.

  • (cs) in reply to Don
    Don:
    I love how he inserts "goodbye" but then checks for "byebye". Great protection in case the Array class develops the ability to convert items to their casual equivalents.

    Not that much of a wtf. It is checking that it is not finding a partial match.

  • IceBrain (unregistered) in reply to Bellinghman
    Bellinghman:
    The Nerve:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.
    And what do you think modern browsers contain? You know, the thingie you use to *run* JavaScript code? Hello?
    Seriously? Ok, maybe they don't teach this in college anymore.
    Or perhaps someone needs to go back to college
    The Nerve:
    A compiler takes code written in a computer language and converts it into machine code.
    Or quite possibly into an intermediate, or byte, code. That's a pretty ancient technology, which goes back to the late 70s in the case of UCSD Pascal and p-code.
    The Nerve:
    JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions.
    The language name may indicate how it was first implemented. So what?
    The Nerve:
    I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX.
    Oh my. No, what you do is to compile it to a bytecode, which then has a per-platform interpreter (or JIT if really required). Why use it? Because a lot of web browsers spend a lot of time executing JavaScript, and if you can speed it up, so much the better.

    You're also making the assumption that the compilation isn't done on the very same platform that the code will execute. For something like, oh, I dunno, Google Maps, it's quite likely that the JS arrives in source form, but that your browser will compile it as soon as it requires executing, and will then carry on using that compiled code till your session ends.

    In fact, V8 already compiles to machine code: "V8 increases performance by compiling JavaScript to native machine code before executing it, rather than to a bytecode or interpreting it."

    And Mozilla is also working on a compiler to machine code called Jaegermonkey, which is slated to be included in Firefox in September.

    People, especially college boys & girls, should know that any language that can be interpreted can also be compiled.

  • (cs)

    But what about null, undefined, false and 0? This unit test needs to be more thorough.

  • (cs) in reply to The MAZZTer

    The ECMAScript Language Specification recently added Array.indexOf() in December 2009. The specification contains no contains() except in the form of the more generic indexOf(). Adding contains() would just be syntactic sugar. This URL links to all editions of the specification.

    http://www.ecma-international.org/publications/standards/Ecma-262.htm

  • CoderDan (unregistered)

    How about TRWTF being that with the same error message you have no indication as to the exact area that it failed LOL

    refoveo: Wow...

  • CoderDan (unregistered) in reply to CoderDan

    Ok, I retract statement. Reread dismal code again.

    enim: rapper

  • Patrick (unregistered)

    Modern computers are getting closer and closer to operating like a human brain. Therefore, it is inevitable that they will start forgetting things every now and then. We have to plan for this now, people! We don't want a Y2100 bug!

  • Jeff Grigg (unregistered)

    I have no problems with this test code. Now that the person who wrote it has a better understanding of JavaScript arrays, it's time to delete this code and move on. ;->

  • Don (unregistered) in reply to Silfax
    Silfax:
    Not that much of a wtf. It is checking that it is not finding a partial match.
    In that case, it'd probably be better to make sure it doesn't find "bye" or even just "b". I don't think I've ever seen a string comparison that would return a match if it found any overlap between two strings. Just think, "frist" would be a match for "brillant". Now that would be a wtf :)
  • Buffled (unregistered) in reply to The Nerve
    The Nerve:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?

    Seriously? Ok, maybe they don't teach this in college anymore.

    A compiler takes code written in a computer language and converts it into machine code. JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions. I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX. The only use for a JavaScript compiler would be so you could write standalone programs that ran faster. If you think the Javascript language has any merits that warrant you creating standalone applications using the language, then check into the psych ward at your local mental hospital. I would rather write lolcode.

    Wow - all of that, and still didn't actually know what you were saying. There's this little thing called "JIT compiling" -- which has been a reality for quite a while now in JavaScript.

    Reference: http://en.wikipedia.org/wiki/Tamarin_%28JavaScript_engine%29 and others

  • Captain Normal Form (unregistered)

    "Functional code" does not mean what you think it means. You only need to test the base cases and the induction case, when you are writing functional code. That is, you encode a proof by induction.

    You can't do that if you're writing stateful code, unless you can manage to do induction over states too.

  • anonymous hater (unregistered) in reply to The MAZZTer

    QFT. Johnny Biggg is wrong

    The MAZZTer:
    "Go tell the company that created Javascript and they should get right on it."

    Except JavaScript does not define .contains or .indexOf

    Thanks for playing, please try again later.

    [Edit: Chrome defines .indexOf but not .contains. Internet Explorer does not define either. Lowest Common Denominator wins, unfortunately.]

    Addendum (2010-07-21 09:27): [Edit: Err, Greatest Common Denominator.]

  • zdux (unregistered)

    alert("This works great!")

  • swedish tard (unregistered) in reply to anonymous hater
    anonymous hater:
    QFT. Johnny Biggg is wrong
    The MAZZTer:
    "Go tell the company that created Javascript and they should get right on it."

    Except JavaScript does not define .contains or .indexOf

    Thanks for playing, please try again later.

    QFP

  • Mike (unregistered) in reply to toth
    toth:
    "Jason, the test is failing!"

    "Uh oh. Okay, seems to be a bug. Go tell the company that created Javascript and they should get right on it. We'll have a fix out to our users in no time!"

    What a useful unit test!

    Testing frequently reveals flaws in vendor APIs. I turns out it's useful to know what the flaws are, and to notify the vendor while you implement a workaround.

  • Verm (unregistered) in reply to Beavis8
    Beavis8:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain?

    Javascript interpreters?

    ha ha ha! nothing like seeing a smart-arse get owned in public to brighten my day. Thanks beavis =D

    Captcha: transverbero (a spanish cross-dressing verb??)

  • luptatum (unregistered)

    JavaScript is the same as Java. It says so right there in the name.

  • (cs) in reply to The Nerve
    The Nerve:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?

    Seriously? Ok, maybe they don't teach this in college anymore.

    A compiler takes code written in a computer language and converts it into machine code. JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions. I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX. The only use for a JavaScript compiler would be so you could write standalone programs that ran faster. If you think the Javascript language has any merits that warrant you creating standalone applications using the language, then check into the psych ward at your local mental hospital. I would rather write lolcode.

    Hi. Thanks for being a huge jerk. It makes the internets more useful for all of us. Let me see if I return the favor.

    http://code.google.com/apis/v8/design.html

    Relevant quote: "V8 compiles JavaScript source code directly into machine code when it is first executed. There are no intermediate byte codes, no interpreter. Property access is handled by inline cache code that may be patched with other machine instructions as V8 executes."

  • дà (unregistered) in reply to savar
    savar:
    The Nerve:
    xxx:
    The Nerve:
    A Javascript compiler is a BIG WTF.

    And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?

    Seriously? Ok, maybe they don't teach this in college anymore.

    A compiler takes code written in a computer language and converts it into machine code. JavaScript (see it's right there in the name) is an INTERPRETED language, which means that an interpreter reads the code and executes actions. I doubt that a JavaScript compiler would have any use in a web browser, and you wouldn't want to use it anyway, because then you would have to compile separately for Windows, Linux, Mac, BSD, AIX. The only use for a JavaScript compiler would be so you could write standalone programs that ran faster. If you think the Javascript language has any merits that warrant you creating standalone applications using the language, then check into the psych ward at your local mental hospital. I would rather write lolcode.

    Hi. Thanks for being a huge jerk. It makes the internets more useful for all of us. Let me see if I return the favor.

    http://code.google.com/apis/v8/design.html

    Relevant quote: "V8 compiles JavaScript source code directly into machine code when it is first executed. There are no intermediate byte codes, no interpreter. Property access is handled by inline cache code that may be patched with other machine instructions as V8 executes."

    +1 Win

  • дà (unregistered)

    Guys, this isn't a WTF. Obviously, he was writing for IE6. You know how web developers waste their time on that.

  • ÃÆââ (unregistered) in reply to Jonathan
    Jonathan:
    The ECMAScript Language Specification recently added Array.indexOf() in December 2009. The specification contains no contains() except in the form of the more generic indexOf(). Adding contains() would just be syntactic sugar. This URL links to all editions of the specification.

    http://www.ecma-international.org/publications/standards/Ecma-262.htm

    Ever heard of prototypes?

Leave a comment on “Testing Fundamentals ”

Log In or post as a guest

Replying to comment #315053:

« Return to Article