Saturday, 5 November 2011

Javascript and the future of code in browsers

Here's an observation; Javascript (the lingua franca for code in browsers) is transforming from a programming language to a specification for code generators, an IL if you will.

Popular tools like CoffeScript, and more experimental ones like ClojureScript and Google Dart are just some examples. That's great right? Well, yes kind of. Developers gets better tools and can be more productive / write more correct programs. However, this can be seen as another form of obfuscation because the output is anything but readable. The output is certainly not small, leading to slower websites. The famous Dart "hello world" example being some 17000 lines of javascript.

Javascript is not well suited as an IL. We can do much better. What if the had a proper managed runtime in common for all browsers? Think JVM or CLR. Something actually designed to be an IL, and not a crippled language taken by surprise once again. This would mean that, with the right compiler, you could use any language you wanted for your web development. Heck, you could use any combination of languages you wanted. I really like the sound of that!

One obvious objection to this idea is that we don't want binary blobs in our HTML pages, it should be readable. But how readable is obfuscated Javascript anyway, especially if it has been code generated? The statement that IL isn't readable doesn't really hold true either, check out what you can do with reflector or java decompilers. That stuff is pretty readable if you ask me;



So how would the HTML with this code look like? Well, the obvious way is to put the link in there;
Or we could use the byte codes directly;

Another example is to put the blob in there;
With good APIs, we could merge stuff like WebGL into this thing. And given that it's a proper IL, we could make the runtime run really fast, using JIT compilation etc. This would eliminate the need for "inventions" like Google NaCl, which is a bad fit for the web if you ask me. Also, any Java or Silverlight plugins are not needed anymore.

I can't shake the feeling that Google missed a great opportunity when they announced Dart. They were thinking to small. Dart should have been an proper IL instead of a new language and a new language specific runtime.

4 comments:

  1. Great minds think alike -- I've been talking about this problem for years ;-)

    I had some hopes for Dart, but it's looking to be yet another kluge. Sadly, the browser makers do not seem interested in solving this problem, as "JavaScript should be enough for anyone" to rephrase a famous misquote...

    ReplyDelete
  2. Indeed, the JS/browser are speeding into a brick wall.

    Full (and proper) VM is the only way to go.

    ReplyDelete
  3. > ... Google missed a great opportunity ...

    Not surprising. As Alan Kay has said on several occasions, the designers of the _Web_ were thinking too small -- that the browser should have been a sandboxed OS capable of interpreting downloaded bytecode.

    ReplyDelete
  4. @Michael Thanks for the Alan Kay reference. Do you think it's too late to get rid of JS? A company like Google has the firepower to drive such a thing through perhaps? At least they could if they weren't so split between Dart, NaCl and whatnot. If they put together a great VM, and rallied their troops around it, then maybe?

    ReplyDelete

Note: only a member of this blog may post a comment.