Saturday, May 28, 2011

Javascript : The Next Great Language

In the beginning there was C.  This was the first Great Language to transform the modern era.  The strength of C is its portability and execution speed.  "Portable Assembler" is the magic phrase that captures its essence.  If you need to talk to the metal directly, and you aren't concerned too much about the specifics of the hardware, this is THE language.

The problem with C is that its intended audience is the computer.  One has extremely fine control of the hardware, but with great power comes great responsibility.  For large complex programs that interact with users or other systems, the flexibility and control turns into a liability.  Also, as a language C lacks a way to create useful abstractions which makes it difficult to compactly describe higher-level concepts.

Over the years many languages have been built on top of C, extending the language while attempting to keep all the good things C offered.  The dominant languages (or language extensions) turned out to  be C++ and Objective-C.  The main benefit these languages offer is the ability to program in an Object Oriented mannor.  C++ in particular came to be the Great Language of the 80's and 90's.

C++ turned out to have problems of its own however.  One spends a significant amount of time focused on 'housekeeping' rather than solving the larger problem, and it's object model in many cases led to a new set of complexity problems.  And so Java was born.

Like C Java offered a new level of abstraction for hardware interaction.  The JVM was the key to Java's success.  The JVM combined with Garbage Collection freed the programmer from many of the concerns about hardware.  And so Java became the Great Language of the late 90's through the 00's.

Java the language was not free from problems however.  In a rush to make java perform well, the evilness of primitives were included in the language, and methods were demoted to second class citizens.

The real challenge for Java is simply that the landscape of computing itself changed.

Recently the Web has gained dominance, and with it the abstraction of Machine/Hardware has been retired in favor of the DOM tree and Services.  Today large applications run on the Web, and increasingly most people think of the Web as an Operating System all its own.  And as C is to Unix, C++/Objective-C is to Windows/Mac, and Java is to JVM, Javascript is to WOS (Web Operating System).

As a language Javascript has much to recommend it:  It is FULLY OO (no nasty primitives, try 1..toString() it works!) with Functions as first class citizens (allowing Functional Programming).   It is Dynamically Typed, has Closures, and natively supports Regular Expressions.  It's simplicity and elegance (keywordssyntax) rivals C. Not to mention that the event-loop paradigm appears to be winning over the multi-thread model. That is the stuff it has had for years, here is the new stuff that has finally pushed it over the top:

  • Thanks to Google's V8 (and Firefox's Trace/JagerMonkey) Javascript is now Fast!
  • With the advent of Node.js Javascript now has access to the backend as well (using the same language for both the front and back end leads to all sorts of efficiencies from code re-use to ease of communication between client and server).
  • With HTML 5 and the Canvas tag, all things UI related are now possible.

All is not roses of course.  Javascript still has to get over some hurtles.  Hurtle #1 is probably the name of the language itself.  It has nothing to do with Java, and 'Script' makes it sound like a dumbed down toy language or DSL which it definitely is not.  The second problem is also in a way what makes it exciting: Javascript is young!  Yes it has been around for 15+ years, but nobody really took it that seriously, so there is a lot of stuff missing that is being addressed by things like the CommonJS project.  There is still a lot of room to be explored, even in something as simple as programming style issues (what is the best way to specify a function associated with an object?).

So Javascript gets my vote for the Great Language of the current age.  It is the language that I personally plan on using for all future projects from iPhone development, to shell scripts, to of course web applications.  It's extensible, flexible, and I think it has within itself the power to create and power a whole new world of exciting possibilities.

No comments: