|
Aug 04
2008
|
ECMAScript 4: Interesting language but poor successorPosted by Christopher Diggins in Programming Languages, JavaScript |
I have been looking over the ECMAScript 4 overview paper (http://www.ecmascript.org/es4/spec/overview.pdf) and my conclusion is that it is an interesting language with lots of potential, but that it violates the spirit of previous versions of ECMAScript.
In case you aren't a language nerd like myself ECMAScript is the core language behind many popular languages like JavaScript, JScript, ActionScript, etc. What I liked about early versions of ECMAScript was that almost any level of programmer could read, write, and understand ECMAScript code in almost no time. This was one of the core ideas of the language: to make it an appropriate scripting language. It's simplicity is why it so darn successful.
I expect a new language iteration to correct major flaws, reduce ambiguity in the specification, and make small tweaks to the language. ECMAScript 4 does this, but it also adds a type-system, new binding primitives, and a dozen other new features! What seems to have happened, is that the designers are attempting to turn ECMAScript into a language that is appropriate for larger scale programming.
Here is a quote from the introduction to the overview document:
ES4 is compatible with ES3 and adds important facilities for programming in the large (classes, interfaces, namespaces, packages, program units, optional type annotations, and optional static type checking and verification), evolutionary programming and scripting (structural types, duck typing, type definitions, and multimethods), data structure construction (parameterized types, getters and setters, and meta-level methods), control abstraction (proper tail calls, iterators, and generators), and introspection (type meta-objects and stack marks).
Of course these are all good ideas for a general-purpose programming language , but are they really appropriate for ECMAScript's original intended usage?
To get an accurate sense of what kind of impact the changes will have (the paper does a poor job of conveying this), I recommend downloading the reference implementation ( http://www.ecmascript.org/download.php ) and take a look at the "builtins" folder which contains implementations of the standard library. In it you will find code like the following:
__ES4__ class Map.<K,V>
{
static const length = 2;function Map(equals=function(x:K,y:K):boolean
{ return x === y; },
hashcode=function(x:K):uint { return hashcode(x); } )
: equals = equals
, hashcode = hashcode
, element_count = 0
{ }meta static function invoke(x : Object!) {
let d = new Map.<EnumerableId,V>;
for ( let n in x )
if (x.hasOwnProperty(n))
d.put(n, x[n]);
return d;
}
...
}
Nothing wrong with this as a general-purpose statically typed programming language, but it isn't what I want from a scripting language. There are too many features now. I am a pretty experienced programmer, but the meaning and correct usage of all the new features will require some study (unlike the original ECMAScript).
So what would my suggestion be? Fork ECMAScript 4 into two branches, one that simply improves the ECMAScript 3 specification and keeps the overall spirit of the language, and another that goes and adds all the fancy programming language features they want (call it E4?). In other-words leave the kitchen sink out of my ECMAScript.

written by Roger Voss, August 09, 2008
As such AS3 is widely used now in practice due to popularity of Adobe's Flex RIA solution. (I'm involved with multiple Flex-based products.)
I've heavily used Object Pascal, C++, Managed C++, Java, and C#.
Relative to those languages, AS3 borrows some of the OOP package and class concepts, such that OOP is first class in the language now, but retains overall a very nice, yet expressive simplicity.
The compile-time static typing is not at all syntax cluttering, and it does aide large team development - and especially clarity of code for long term maintenance. The last attribute is especially important for enterprise apps - which live for much longer than the PHP web page stuff that Yahoo cranks out like sausage.
None-the-less, AS3 retains some of the goodness of original javascript in terms of using functions as closures. It has very nice facilities for doing out-right functional programming in combination with the array classes and certain methods those support.
It also has mechanisms to escape static type restrictions and allow for dynamic programming behaviour at runtime. There is a performance cost for using that, so it's nice that there are judicious means to enable it where it's deemed useful, but otherwise be under static type regimen as the default mode.
Relative to Java and C#, and relative to original JavaScript (which I confess I did not care for much at all, though I like some of its capabilities), I've found AS3 a very decent language for doing what it was designed for - programming the GUI of RIA apps that run in a browser. For that purpose it strikes a very good balance indeed. Also, folks are able to learn and pick it up very quickly. (Mastering its potential for functional programming would take longer, but that is not essential in order to be immediately productive in writing decent OOP code.)










ECMAScript 4 seems to take backwards compatibility seriously, and it's my understanding that you don't have to use any of these advanced features if you don't want to. The idea of gradual typing seems to be good, and I blogged about it at length here: http://hamletdarcy.blogspot.co...rator.html
I get the impression that the language is trying to continue supporting the lower end/scripting pieces while also offering better constructs for the high end/framework writers. This is good. Personally, I'm excited about ECMAScript4 and would urge others to read several sources before claiming that it has blown its complexity budget.