WAT! JavaScript, Ignorance And Prejudice
Written by Mike James   
Monday, 17 June 2013

It is easy to make fun of a language when you don't really understand it and are simply comparing it to what you already know. JavaScript suffers a lot from the WAT! style of humor. So does it deserve it?

You must have encountered the WAT! meme somewhere on the web. The idea is simple - you present some aspect of a language to a group of programmers, demonstrate how stupid it is on the basis of what it does, and finish off with a WAT!

And a big laugh.

The target is more often than not JavaScript and the result is that the perpetrators of the WAT end up showing how narrow their experience of programming has been. 

 

 

Why is JavaScript so often the butt of the joke?

Part of the reason is that it is a language that beginners pick up and never quite mange to learn - so they end up churning out some very bad code. It is also the case that JavaScript looks like a trivial language; this means you can get a long way without having to learn anything new so, again, the result is bad code. Many programmers think that when they see bad code in a language then it is the language's fault. Of course you can see bad code in many languages. But JavaScript has a repuation for it that goes well beyond what seems reasonable.

Perhaps because JavaScript is just different and we all know that it doesn't pay to be different.

Different isn't the same as bad. Sometimes I think that Douglas Crockford did JavaScript a great disservice by writing JavaScript: The Good Parts because it advertised an all-too-clear message that JavaScript was so bad that it needed the few things that were good about it listed in a book. It has to be partly responsible for the way that you hear programmers saying how awful the language is and then adding,"but I've never used it". By saying that JavaScript had some good parts, Crockford gave authority to everyone who wanted to say that it was bad.

Programmers coming from a strongly-typed, class-based language more or less completely misunderstand JavaScript and never realize that their complaints and "WAT" jokes simply reveal that they haven't a clue wat they are doing.

 

wat

 

Let me give you an example. Suppose I just picked up a little bit of Java (replace by your favorite class-based, strongly-typed language) and were presenting a WAT! to a group of JavaScript programmers. First you would show how Java lets you get some data from a UI component:

String cost = UI.getCost();
float tax=cost*0.1;

First off you have had a small laugh at the use of String and Int. But your audience now falls about laughing when you show the error message that results from trying to compute the tax. WAT! you have to convert the user input from "100" to 100 how stupid is that! After that you can all have a really good laugh when it is revealed that, even after converting the String to an Integer:

float tax = Integer.parseInt(cost)*0.1;

it still doesn't work! Yes Java has two types of floating point data and 0.1 is a double, not a float! 

You can now all sit back and wonder why Java has anything so complicated when all you need is a floating point type that can represent integers accurately over a very big range - just like JavaScript. Why bother with a distinction between 1.0 and 1, and even more silly is the distiction between 1 and "1". 

JavaScript does it differently and this doesn't mean its wrong any more than Java's strong typing is "wrong". 

javacrack

You can continue in this way making Java or any other class-based, strongly-typed language seem broken in hilarious ways. For example functions that return "void" - what's a void, is it an object, can you smoke it?

Then you can put together an example where a function needs to be passed to another function - only to discover that it can't be done. WAT! functions can't be defined outside of an object... you can't pass a function argument! Java is only just getting round to adding lambda expressions?! And so on...

The point is that this is more a clash of cultures than a proof that anyone's language is laughable. 

There are problems in JavaScript that make it harder to use than it should be, and there are parts of it that are more error prone than they should be, but the strange thing is that they aren't the parts that most WAT! examples use for their laugh. Yes, they are mostly laughing at the good bits because they haven't taken the time to learn the language. 

And please don''t try telling me why Java does things in the way that it does - this isn't about the merits, or otherwise, of strong typing, class-based objects or functions as second class citizens. This is about how any language can seem extreme in its approach if you don't share the understanding and motivation of the language. I don't really think that any of the WAT! examples of Java  are funny and I don't think the approach is unreasonable, but I do want you to try and imagine that this isn't the only possible way and programmers from other persuasions could, and do, find Java's approach less than natural and far from logical.

Strong typing isn't the only way to do things, neither is a class-based type hierarchy the only approach to objects. It is important that we find out about different ways of organizing what we do, and if things seem strange and even silly - remember they might be just different.

 

Related Articles

JavaScript Is Basic's Offspring

Why JavaScript is a Jem

JavaScript Inherits the Earth

JavaScript: The Good Parts (Book Review)

 

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

Banner

 

blog comments powered by Disqus

<ASIN:0596517742>

 

Last Updated ( Monday, 17 June 2013 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.