JavaScript: The ManBearPig of Programming Language

October 20, 2008 at 09:09 AM | categories: javascript | View Comments

In the last few days, I got the chance to play with a bit of JavaScript at work. As someone who has near zero JavaScript experience, it appeared to me that it is a language with little conceptual integrity. Some examples:

  • Objects are associative arrays, but unlike arrays, they don't have any helper function or attribute (because objects are associative arrays). It says a lot about the language design when arrays have reduce() while associative arrays do not even have length.

  • There is no function overloading, and default parameter can't be specified either. Fear not - you are blessed with the magical arguments, and the warm and fuzzy feeling from coding a command line app.

  • JavaScript 1.8 added a lambda notation that gave the braces another meaning. A pair of braces create an object. A pair of braces also form a code block. If your have a one-line function followed by an opening brace, you need a return. Otherwise, you don't.

  • jQuery has a each function that associates a true return value as continue and a false return value as break. prototype has a each function that used to associate a $continue exception as continue and a $break exception as break. Desperately wanting a piece of "anonymous function does not always return a value" warning, it now associates any return value as continue.

  • Python got PEP8, Java got code convention, JavaScript got sparse style guides that do not conform to each other. Nobody seems to referring to them anyway.

In short, there is no equivalent word for Pythonic in the land of JavaScript. As a programming language, JavaScript is just like ManBearPig, with limbs and body parts from different animals attached together at random to create the ferocious monster:

Not unlike ManBearPig, people easily get confused when it comes to defining JavaScript. Is it half man-bear, half pig? Or is it half man, half bear-pig? Look at this question posted at stackoverflow, seeking the real identity of JavaScript:

There have been some questions about whether or not JavaScript is an object-oriented language. Even a statement, "just becuase a language has objects doesn't make it OO ".

Is JavaScript an object oriented language?

And here's my favorite answer with a +8 (emphasis mine):

Javascript is a multi-paradigm language that supports procedural, object-oriented (prototype-based) and functional programming styles.

Half man, half bear, half pig. That's a ManBearPig in my book.

Of course, by rephrasing a little, we can get a more correct answer:

JavaScript is a programming language that looks pretty much object-oriented, but aspiring to be a functional one, yet being used the most to create procedural code.

Trying to clean up the image of JavaScript, Douglas Crockford kept telling us that JavaScript is the world's most misunderstood programming language. Which is, of course, the same as saying ManBearPig is the world's most misunderstood animal. Duh.

Anyway, enough with the JavaScript bashing, which is not the point of this post. You see, this is all part of Al Gore's effort to spread ManBearPig awareness. Al Gore invented the Internet, which then gave birth to JavaScript that closely resembles the evilness of ManBearPig. He just wanted to subtlely tell the world how dangerous ManBearPig is, by giving us this reckless languauge called JavaScript. Thus, let me end this by saying:

"Thank you, Al Gore. You are super awesome."