Rant : ECMAScript 4.0

I love JavaScript.

I love JavaScript because it is a simple, concise, prototype based language. Usually, when a language evolves, bugs get corrected and a few features are added to it. This is not the case with JS: ES4 is a completely different language, and yet it is supposed to be JS2. Of course there are some aspects of ES4 which are very interesting, but when you add everything up, ES4 just sucks.

Pros :

  • Non nullable values
  • Expression closures
  • Proper tail calls
  • Meta level hooks (though those should just be special methods of objects)
  • this preservation for nested function calls
  • Array comprehension (concept, not syntax)
  • Destructuring assignement
  • Triple quoted strings (though multilines strings could be nice…)
  • Slicing syntax
  • &&= and ||=

Cons :

  • Typing system : javascript is a script language, if you need a static and strict typed language, use OCaml
  • Records : overlap with objects
  • Classes : JS is prototype based, classes suck
  • Lexical block scoping using let : what's the point ?
  • Iterators
  • Generators
  • 1000 different types of numbers
  • Interfaces

In fact, I'm under the impression that ECMA is trying to transform JS in something like Java1. And this is bad, very bad. Of course JS needs some improvements, but all those stupid features are not, they are pollution.

  1. Did I ever say Java sucked, by the way ? []

8 Responses to "Rant : ECMAScript 4.0"

TNO says:

Before jumping to conclusions about this long overdue evolution, you may wish to read this discussion:

http://lambda-the-ultimate.org/node/2504

Zsolt says:

We JS developers should talk to the Actionscript people, they went trough what we are about to go trough so they should know if types, classes and all that are better then what they had before….or if not.

Adrien Friggeri says:

Actually I have read that whole thread TNO, and what I can see is that there is no massive adhesion to ES4.

It seems that 50% like it, and the other 50% think that ES4 has nothing to do with JS 1 anymore…

TNO says:

@Zsolt:

Those Actionscript peopl (Adobe) are on the committee for the development of the language actually, and one of the largest contributors.

@Adrien:

Its not as if the current language is being replaced, as was said most everything is optional. You will still be able to do type="text/javascript" and keep on trucking. For those who want to go beyond simple rollovers and basic Ajax have the option of full blown typed compiled code as type="application/ecmascript;4" or whatever its mime type happens to end up being. Have you taken a gander at these yet?
http://developer.mozilla.org/presentations/xtech2006/javascript/
http://developer.mozilla.org/presentations/eich-media-ajax-2007/

Adrien Friggeri says:

I just looked at those two presentations, and this is what is striking : "Yes, this was the Java dream that died in 1995, or 1997".

That's exactly my point : JS should not be the new Java.

Moreover, with ES4 being class based, there won't be anymore widespread prototype based language, which is a shame.

One last thing, the reason why all those changes are added is not to have a better JS, it's just because most web developers are unable to adapt to another paradigm : they write JS code as they would write Java code, which is wrong

Douglas Crockford shows how to implement most of classical object orientation, and yet some lazy devs beg for a class keyword..

Just to give you an other example : what if tomorrow some comittee would decide to turn lisp, haskell or ocaml into an imperative language, because devs are too lazy to code in another paradigm ?

Of course, this will never happen because the guys designing those languages are driven by what they think is a good language, not by browser vendors…

The other terrible thing is that whereas you can choose to use C, C++, Java, Python, Perl, Ruby, Haskell, OCaml, Visual Basic or whatever when you write an app for the desktop, you have no choice when it comes to the browser. And the whole point of "it's optional" is utter bullshit : as soon as ES4 will be implemented you'll have a lot of libraries being ported to ES4 (say, scriptaculous, moofx, etc.) by the same guys who have added a simili class based system is the mainstream frameworks. When that will happen, it won't be possible to use nice libraries AND JS1.

The worse thing about that ? We don't even need a new language, we need bugfixing in JS

TNO says:

Classes are not replacing prototype, and Brendan discussed the reasoning behind adding it:

http://lambda-the-ultimate.org/node/2504#comment-37668

All of this wasn't added to pander to some lazy Java guys, its to solve real world problems. (For example, I'm sure you know how much of a hassle it is to create a TRUE singleton)

"Just to give you an other example : what if tomorrow some comittee would decide to turn lisp, haskell or ocaml into an imperative language, because devs are too lazy to code in another paradigm ?

Of course, this will never happen because the guys designing those languages are driven by what they think is a good language, not by browser vendors…"

Google and Adobe aren't browser vendors, and they have a heavy vested interest in this development (So they don't have to use C# or some crap). Actionscript is already using a lot of this specification already.

You DO have language options on the web, but it requires plugins and downloads which is another reason why ES4 is coming about. Do one language and do it well. Plus Its not exactly practical to expect a mobile web browser to support 4-5 language engines currently.

"…as soon as ES4 will be implemented you’ll have a lot of libraries being ported to ES4 (say, scriptaculous, moofx, etc.) by the same guys who have added a simili class based system is the mainstream frameworks. When that will happen, it won’t be possible to use nice libraries AND JS1."

Without a doubt I expect the major libraries to port versions to ES4 and keep current versions, but you can't forget that backwards compatibility is a high priority for the committee. I'm not sure of the details, but there will be a JS2 -> JS1 translator available to serve code to older browsers.

So does that mean people won't even be writing ES1 code anymore? I don't think so. Browsers are not required to implement this version.

We can also probably bet that Microsoft will ignore this entirely so JScript will be around for along time. ASP, webpage JScript, WSH on the client, etc… Its not as if ES3 is disappearing the day ES4 fully released.

TNO says:

Almost forgot to mention, Firefox plans to support Python in the future.

David says:

Why do people think that ES4 will be used for the web any time soon? More likely it won't be used much on the web for another 5 years. Why you're jumping up and down complaining about losing JS is beyond me, because you're not.

ES4 is addressing real problems with JS that affect real world problems. Sure, maybe 90% of those real world problems have nothing to do with web scripting. But guess what? JS is no longer a web scripting language. It is used for scripting graphics applications (Photoshop), 3D applications (XSI), Web Browsers (Firefox) etc.

"Typing system : javascript is a script language, if you need a static and strict typed language, use OCaml"

Being a scripting language has nothing to do with being static or strictly typed. You can still have a typing system and still be dynamic and loosely typed.

"Classes : JS is prototype based, classes suck"

Err… then keep using prototypes.

Leave a Reply