Four myths about JavaScript

Add comment!

April 29th, 2009

Hey guys, we are using JavaScript for the scripting system in Overgrowth. Unfortunately, every time we bring it up, we get a lot of flak about the language. Here are a few common misconceptions and my response to each of them.

Overgrowth Console

Myth 1: JavaScript is just a clowny version of Java
JavaScript is actually totally independent of Java. The only thing it shares is slightly similar syntax. The reason why it has Java in its name is due to marketing reasons. According to Wikipedia, "The language's name is the result of a co-marketing deal between Netscape and Sun, in exchange for Netscape bundling Sun's Java runtime with their then-dominant browser." JavaScript is a brand new language that shares much more with functional languages like Lisp or even Scheme than with Java.

Myth 2: JavaScript is loosely defined and unpredictable
JavaScript is very specifically defined. Google's V8 Engine adheres to ECMA-262, 3rd Edition which has no room for misinterpretation. V8 and other JavaScript engines have literally thousands of test cases to verify that they stick *exactly* to the specification. When people say that JavaScript has a lot of inconsistency, they are probably confusing JavaScript with DOM APIs* which are notoriously fickle between browsers -- namely older versions of Internet Explorer.

*DOM APIs are basically an API for JavaScript to interact with the browser, for example, adding new text to a webpage, or calling a function when the user clicks on a button.

Myth 3: JavaScript is very slow
JavaScript is actually quite fast. It is very optimized and keeps getting more and more so -- look into Google's V8 (which we are using), TraceMonkey, Squirrelfish Extreme, etc. A ton of companies have HUGE vested interest in optimizing JavaScript and JavaScript performance increases all the time. Browsers live and die by their JS execution performance so there is a lot of original research in this area.

Granted, it is not as fast as a compiled language like C, but we don't need it to be. Our scripting engine is not the bottleneck in Overgrowth, which basically means that even if the V8 JavaScript Engine got a 200x performance boost overnight, your Overgrowth FPS would not be increased.

Myth 4: JavaScript is a crappy language and only suited for small browser tricks
JavaScript is actually an awesome dynamic language that can definitely stand tall. JavaScript features prototypal inheritance which is hard for a lot of people trained in classical inheritance to wrap their heads around. This often leads to claims that JavaScript is not object oriented, doesn't support complex programs, etc.

Well, actually JavaScript does support classical inheritance as well, and with a few coding patterns, people trained in languages like C++ or Java should be ok.

JavaScript is a dynamic language and this lends itself to a lot of cool behavior. Here is a demonstration of how you can take advantage of higher order functions from my friend, Chris Pennello, CTO of Redux. This is an implementation of Python's functools.partial:

function partial() {
var f = arguments[0];
var a = Array.prototype.slice.call(arguments,1);
return function() {
return f.apply(this,
a.concat(Array.prototype.slice.call(arguments)));
};
}

This will take a function as its first parameter (a function is simply an object in JavaScript) and return a new function that calls the original function with the remaining arguments.

This is just the tip of the iceberg. This site has all sorts of functional programming niceties that Python programmers are familiar with: map, reduce, zip, select, etc.

Post your questions or comments about JavaScript below and I'd be happy to answer them.