Post news RSS Four myths about JavaScript

Whenever we mention Overgrowth's scripting system (which uses JavaScript as the core language) we get attacked. Here is my defense of the JavaScript language and V8 implementation, inspired from some ModDB comments on our page.

Posted by on

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:

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

(permalink)

Comments
awesomepossum
awesomepossum

That is rather nifty, I though it was mostly just a website code thing.

Reply Good karma Bad karma+6 votes
jeffr Author
jeffr

Always happy to spread the word :)

Reply Good karma+4 votes
Jyffeh
Jyffeh

All I know is that any thing I've ever used it for turned out pretty bad.

That also could be blamed on the fact that I just suck at coding though.

Reply Good karma Bad karma+6 votes
chris_sloany
chris_sloany

hmmm, intresting!

Reply Good karma Bad karma+3 votes
Daystranger
Daystranger

Yeah, yeah, but you should've used LUA instead. ;)

Reply Good karma Bad karma+2 votes
Dotmister
Dotmister

Lua has a really stupid syntax, JavaScript is much more intuitive to a C++ programmer.

Reply Good karma Bad karma+4 votes
Robots!
Robots!

Very much agree.

Reply Good karma Bad karma+1 vote
Silverfisk
Silverfisk

Seems pretty great to me! I know a bit of Java and C++ so I hope that'll help me when I'm gonna mod OG. :-)

Reply Good karma Bad karma+4 votes
Daystranger
Daystranger

Just need to remember some differences and exclusive functions for each language.
Anything else like if-then or loop stuff and math is pretty much the same.
I've studied Pascal and C++ as student.
Now I've learned Lua myself without any books and stuff. Just by looking at other's code.

Reply Good karma Bad karma+3 votes
Range_Finder
Range_Finder

All id say is use the languages your comfortable with. If you can do the things you need to do with them I cant see a reason not to use them.

Reply Good karma Bad karma+3 votes
MuffinSoldaat
MuffinSoldaat

I have to say I'm still not convinced.. examples please?

Reply Good karma Bad karma-1 votes
Arvind
Arvind

A good article, and I agree that for c++ and java guys like me it is much easier to adapt to javascript than, say, lua.

Reply Good karma Bad karma+3 votes
Daystranger
Daystranger

Lua is almost same thing as C++

Reply Good karma Bad karma-2 votes
jeffr Author
jeffr

Maybe if you squint your eyes really hard. ;)

Reply Good karma+4 votes
Dragonlord
Dragonlord

Just some notes before "down-vote" happens again.

Cloning objects is not inheritance. There is not "classical inheritance" ( what exists is single or multiple inheritance ). Inheritance is a hierarchical construct while cloning is a single operation ( it clones an object namely it's dictionaries ). Not that cloning is bad ( it allows to mess with objects in Python in neat and interesting ways ) but it's not an inheritance equivalence. The two work different and have different properties.

And a dynamic language is not a requirement for implementing functional programming ( aka continuation ). It is implemented also in non-dynamic languages.

Reply Good karma Bad karma+2 votes
jeffr Author
jeffr

Can you give an example of what you mean by JavaScript can't do classical inheritance? As I mentioned, this shows how JavaScript can do that: Javascript.crockford.com I'm curious to hear your use case so I can concretely explain how to do what you're asking instead of just linking to Crockford.

I'm curious which languages you are referring to that have higher order functions but are not dynamic languages.

Reply Good karma+2 votes
inventivedingo
inventivedingo

D is a statically-typed language with higher-order functions. So yes, you can do currying and whatnot. See: Hans-eric.com

Which is really cool, since it means you can write programs which freely mix imperative and functional styles and compile them to native code... all in a language which will feel very familiar to C++ and Java programmers, albeit friendlier and more expressive respectively. :-)

Did I mention that D totally rocks? It totally rocks.

Reply Good karma Bad karma+1 vote
INtense! StaffOnline
INtense!

I must admit I felt JS sucked before frameworks like JQUERY showed me how powerful it can be.

Admittably this was because I was using JS for HTML manipulation which (as pointed out in this article) is a nightmare due to differences in interpretation between browsers.

Reply Good karma+4 votes
jeffr Author
jeffr

jQuery is amazing. :) We include it in Overgrowth so modders can use it.

Reply Good karma+2 votes
Glad-Wrap
Glad-Wrap

jQuery is what bought me back to Javascript, but now I love the language regardless of jQuery. I've been writing some pretty serious OOJS lately and am now interested in getting into some server-side javascript.

Reply Good karma Bad karma+2 votes
hushpuppy
hushpuppy

This would surly be very intresting if i knew anything about programming. But im a stupid artist so ill crawl back to 3dsmax now....

Reply Good karma Bad karma+2 votes
NullSoldier
NullSoldier

Javascript is really interesting, and MANY companies are focusing soley on the power of Javascript such as Google. What really blows my mind is how they treat functions as first class citizens. You can do some crazy stuff with the delegates in Javascript if I remember correctly.

Reply Good karma Bad karma+3 votes
w1ngzer0
w1ngzer0

I wish i could learn programming on my own. I have tried to understand it for too many years. Thanks for spreading the word of java.

Reply Good karma Bad karma+3 votes
solistus
solistus

As a web developer I agree wholeheartedly. The problems people face with JS most frequently are DOM-related issues which are irrelevant to applications of JS that are not in the context of a web browser.

For non-web developers: DOM (Document Object Model) is the way that the browser translates both the content of the current page and certain browser-defined elements like the properties of the browser window itself, titlebar, etc. into an object to be referenced by Javascript. While there is a DOM standard supported by the World Wide Web Consortium (the main standards-and-protocols setting body for web technologies), no browser that I am aware of implements it perfectly; as with just about every standard, most browsers (Firefox, Safari, Opera, etc.) are very close to the standard with a handful of unique bugs or oddities each, most of which rarely matter, while Internet Explorer is miles from the spec. IE's implementation of Javascript itself is non-standard, too, which is the source of some of the notorious 'IE bugs' in web development; technically, IE does not implement Javascript but rather JScript, a proprietary Microsoft dialect that is nearly identical to standard Javascript, but not quite. A lot of the perceived clutter and inefficiency in Javascript code is due to the fact that most 'real' Javascript code has to include browser detection tricks (DOMs don't identify themselves; you have to snoop around for known differences to figure out what browser you're dealing with) and other messy workarounds to deal with the oddities of web scripting. Until you start writing mods designed to run on both Overgrowth and a multitude of clones which make lots of minor, poorly documented changes to the game and scripting engines, most of the headaches of web development won't apply :)

Reply Good karma Bad karma+3 votes
child
child

Thanks for educating the ignorant.

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

News
Browse
News
New
Post news
Share
Related Games
Overgrowth
Overgrowth Adventure
Related Engines
Phoenix Engine
Phoenix Engine Commercial
Related Groups
Wolfire Games
Wolfire Games Developer & Publisher