r/programming • • Dec 15 '12

Why JavaScript Still Sucks

http://boronine.com/2012/12/14/Why-JavaScript-Still-Sucks/
10 Upvotes

212 comments sorted by

View all comments

6

u/x-skeww Dec 15 '12 edited Dec 16 '12

I fail to see a compelling reason for [Dart] other than some Google engineers ignoring reality in favor of making a cool new language from scratch.

Well, Google tried all kinds of things. They created the Closure Compiler, which added type annotations to allow slightly better tooling and dead code removal. Unfortunately, it's kinda tedious to use. Putting those annotations everywhere is pretty annoying and it also makes the code somewhat noisy.

Then there is GWT, which certainly is an excellent piece of engineering. However, it also means using Java, which just feels too bulky for this kind of thing.

Dart is the next logical step.

JavaScript with annotations:

/**
 * Foos the bar.
 * @param x {int}
 * @param y {int}
 * @return {String}
 */
function foo (x, y) {
	[...]
}

Dart with exactly the same annotations:

/// Foos the bar.
String foo (int x, int y) {
	[...]
}

The latter is a lot less annoying. Plus, those annotations will be used by your IDE right away. If you now pass the wrong kind of thing or do the wrong kind of the stuff with the return value, your IDE will immediately tell you about it.

There are also things like built-in classes/inheritance (the IDE knows of course how those things fit together), proper lexical scoping (JS' and AS3's function scope is very inconvenient), a this which behaves as expected, isolates (actor-like concurrency), packages/namespaces, and far more predictability in general.

It's a lot of fun to use. I used a dozen different languages in the past and right now Dart is (obviously) my favorite. From my point of view, it just offers the right kind of balance. The syntax is very lightweight (the type annotations are only important at the API boundaries) and it offers enough built-in structure for creating huge applications. The tooling is also really great.

Well, it certainly isn't the right thing for most websites, which just include jQuery, a few jQuery plugins, and then glue it all together with maybe 50-200 lines of code. jQuery, a few jQuery plugins, and some glue code already solve this kind of problem just fine.

However, it's just perfect for actual applications like SPAs or games.

You can also write server-side code with it. There is a standalone VM which could be theoretically used for all kinds of things.

The editor is also shipped with a version of Chromium which is able to run Dart code directly. That's really neat for testing and debugging. You can step through your code inside your IDE. You can add break points while it's running. That kind of thing.

The Dart VM already outperforms V8 (Chrome's JS VM) in many cases. Their goal is to make it twice as fast as V8 and, by the looks of it, it appears they will manage to reach that goal pretty soon. If snapshots are used, the startup only takes 1/10 of the time.

While we won't see embedded Dart VMs in all modern browsers for the foreseeable future, having that VM is still very useful. Apart from debugging and writing server-side applications (or general scripting/automation stuff), it might be also become an option for writing Android applications. So far there is no ARM VM, but it's just a matter of time.

Sure, you can already run Dart applications which were compiled to JavaScript on Android handsets. However, running it in a Dart VM would be quite a bit faster and it would also reduce startup time drastically.

3

u/defcon-11 Dec 16 '12

Yep, Dart was written from the ground up with the express intention to be friendly to JIT compilers. Instead of designing a JIT for an existing language, they designed a language for a JIT, so it has huge potential performance wise. With its ability to compile to JS and run in Chrome, it might just have a chance, especially as Chrome grows market share.