- 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
AAAAHHH!!!
It's college all over again!
Admin
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.]
Admin
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.
Admin
I'm guessing they're implementing a javascript compiler or interpreter, in which case this is completely not a wtf.
Context missing error.
Admin
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?
Admin
"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!
Admin
TRWTF is getofmymetriclawn's comment.
Captcha: abico, who gives a crap?
Admin
"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.]
Admin
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();
Admin
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.
Admin
Hmmm...
Make a NEW object and see if it's already in the list. That's just funny.
And the spam filter sucks.
Admin
No Unicorns or Pink Ponies today :-(
Admin
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.
Admin
You say goodbye, and I say hello! Hello, Hello!
Admin
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??
Admin
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.
Admin
And what do you think modern browsers contain? You know, the thingie you use to run JavaScript code? Hello?
Admin
Javascript interpreters?
Admin
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.
Admin
You should check out the games that come as default with recent Ubuntu desktop installations. At least one is written in JavaScript.
Admin
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.
Admin
so TRWTF is Alex not knowing Javascript.
Admin
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.
Admin
I had no idea! Unfortunately a theoretical WTF has become a genuine WTF.
Are we ever going to upgrade the freaking internets?
Admin
Err...ActionScript?
Admin
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.
Admin
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)
Admin
java.casualLogic, brilliant!
Admin
Mmmh... He forgot to have a "return true;" at the end of the function.
Admin
Not that much of a wtf. It is checking that it is not finding a partial match.
Admin
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.
Admin
But what about null, undefined, false and 0? This unit test needs to be more thorough.
Admin
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
Admin
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...
Admin
Ok, I retract statement. Reread dismal code again.
enim: rapper
Admin
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!
Admin
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. ;->
Admin
Admin
Reference: http://en.wikipedia.org/wiki/Tamarin_%28JavaScript_engine%29 and others
Admin
"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.
Admin
QFT. Johnny Biggg is wrong
Admin
alert("This works great!")
Admin
QFP
Admin
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.
Admin
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??)
Admin
JavaScript is the same as Java. It says so right there in the name.
Admin
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."
Admin
+1 Win
Admin
Guys, this isn't a WTF. Obviously, he was writing for IE6. You know how web developers waste their time on that.
Admin