Google's JavaScript assassin: Web languages are harder than VMs

The problem with programming languages is that everybody’s got an opinion - just ask Lars Bak, the Virtual Machine guru who is building Google’s planned (by Google at least) replacement for JavaScript.

Bak has spent 15 years working on object-oriented VMs (virtual machines) at Google and Sun Microsystems and notched up 50 patents in the process. He’s responsible for HotSpot, a core component of the Java stack and Java's default VM now owned by Oracle. Also, he developed Google’s V8 JavaScript engine - which was so fast Google had to bring in a new raft of benchmark tests to deliver credible test results for JavaScript in its browser. V8 helped begin a browser JavaScript performance war, one consequence of which was that Microsoft was forced to change how it built Internet Explorer so that it did not have to risk getting left behind by web developers.

The Danish programmer joined Google in 2004 and began work on V8 in 2006 with Google software engineer Kasper Lund, but it was in 2010 that he started Dart – a class-based language inspired by SmallTalk, Java and C++ and supposed to be faster than JavaScript. Google’s objective is that Dart will eventually replace JavaScript as the "lingua franca" of web development.

That's a big objective. JavaScript began as the last dying gasp of Marc Andreessen's defeated browser outfit NetScape at the end of the 1990s. The Netscape language became an Ecma International standard in 1997. Sixteen years later, JavaScript is number 10 in the world ranking of programming languages and has inspired a head-aching number of libraries and development frameworks from those who know and love it.

Fresh off his success on VMs, the idea for Dart was a simple idea - to improve the state of the art of client-side web development. “We just want to improve the web platform... so that it’s easier to write bigger apps,” Bak tells The Reg during a recent interview as Dart marked its M1 delivery.

He's grown up a lot since then.

“I have learned it’s much harder to do a language than a virtual machine,” Bak confesses. “People are extremely opinionated when doing a language,” he says, before the Dane adds: “But this is great – I see that people care. I have learned that you have to do it properly.”

The problem is the curly-bracket heads just don’t accept your work as happily as most of them would accept any VM that's handed to them.

“The initial reaction to doing another programming language is people say: 'We have one that’s sufficient'. Change can be hard for some people. The other reaction is when you design the programming language [Dart] you [try] to make it simple so people can use it in an hour, so the other category of comments is: 'It’s a bit simple for me'."

“Some from the academic world expect more complex constructs but my view is if you don’t make it easy for ordinary programmers you don’t have a chance of success. That’s why the land has curly brace syntax and single inheritance.”

'I have learned it’s much harder to do a language than a virtual machine... People are extremely opinionated when doing a language' - Lars Bak

That’s meant a lot of heavy lifting so Bak hired an engineer to work on Dart’s semantics. When we spoke there had been 12,000 revisions with a new version every six to eight weeks. Since we chatted there's been an M2 release with more revisions. Dart 1.0 is now due this summer, Bak tells us, when the language should be finished and delivered along with a “good” set of libraries and a “good community of people using Dart.”

The unfinished part, ironically, is the Dart VM and that’s vital because without it, Dart can’t complete Google’s mission to infiltrate the world’s browsers. Without the VM, the Dart source-code file will generate JavaScript code. The VM is also essential to some of the high-speed start-up stuff that Google’s Dart team has planned. The Dart VM is currently only in Chromium, the open-source basis of Google’s browser.

Building a language might be hard but what is arguably the most demanding part still lies ahead: adoption. Google and Dart must convince web devs, browser-makers and major websites like Facebook and Digg to surrender their love of JavaScript for a brand new language from Google - a partisan player on the web with whom many are competing.

Before Dart even gets to this stage, though, it must convince the Googleplex that it is the future and that JavaScript is the past. Google is heavily invested in JavaScript with Gmail, Google Analytics and its homepage on JavaScript.

Google itself is the first domino that Bak needs to tumble - and it's a heavy one. “If we do not to prove ourselves the obvious benefit of using dart then Google will not convince other browser makers. My plan is to demonstrate better performance,” Bak admits.

No Googley magic wand

Just because Dart is Google's baby, that doesn't mean Dart is a shoo-in.

“Google is a big company and people are deciding what tools are most effective. I have to walk around and make sure people can see the advantage in using Dart,” Bak says. “So far so good, but no - there’s no magic wand inside the Googleplex. I don’t expect that everything to flip over next summer and that’s fine. It takes time to get a language popular inside and outside the company.”

Dart is pitched as the language needed to build the kind of complex web properties owned by Google that the Dart team claim tax JavaScript.

Dart consists of the language under a BSD licence, libraries and editor. Like JavaScript, Dart uses C-like syntax and keywords. JavaScript, though, is a prototype-based language whereas objects in Dart are defined using classes and interfaces – just like in C++ and Java. You can also declare variables using static types. By borrowing from C++ and Java, the idea is Dart is familiar yet even easier and quicker to code in, and should generate fewer bugs – called side effects.

Bak claims Dart’s object model is simpler and more structured than the object model in JavaScript. The payoff is that applications start faster and are more efficient, doing a smaller number of computes and not straining garbage collection. You can also allocate an object to a known field and you can group objects, cutting down on any unwanted events that divert processing power.

'I have no problem with JavaScript'

Bak reckons Dart is ideal for Gmail. Google's email service has 1MB of source code that must be read before starting, but Dart’s structure lets the VM take a snapshot that’s stored in the browser, which can be booted up in one-tenth of the time it takes to load the full code from scratch. “That’s hard to do in JavaScript because in setting up the program you have to execute the source code; that source code has side effects and those side effects cannot be snapshotted,” Bak said.

Dart helps on things like 3D gaming. A detailed structure of objects means the VM doesn’t have to take time running floating point connections to run new objects, which puts extra pressure on the garbage collector.

Bak now reckons Dart runs 30 per cent faster on Google's V8 than JavaScript under the Richards operating system kernel simulation benchmark and under the DeltaBlue benchmark – two standards used at Google. The goal is for Dart to become twice as fast.

Technology is one thing but overcoming the industry’s politics is a factor, too.

Bak's team has two hurdles to clear. Firstly, Apple, Microsoft, Mozilla and Opera will need to be convinced of the technical merits of Dart. But secondly, they will also need to be persuaded that Dart is not a cuckoo's egg that Google is trying to lay in their browser nests to take over the internet, that it's not a means to plonk them on a Mountainview roadmap or shoehorn them into helping Google’s search, advertising and web properties to the detriment of their own.

That memo on replacing JavaScript won’t help - it was strongly worded stuff. Googler Mark Miller in 2010 wrote: “The goal of the Dash [the initial name for Dart] effort is ultimately to replace JavaScript as the lingua franca of web development on the open web platform,” he said.

“This is not taking anything away from JavaScript... we have to make sure the web really competes well. With the mobile ecosystem we have to do a lot of innovation in the browser,” Bak said.

“While Dash is catching on with other browsers, we will promote it as the language for serious web development on the web platform," Miller continued in his October 2010 internal memo.

Google was promising to play nicely and be a good member of the JavaScript team, evangelising it in public for the next version of JavaScript – codenamed Harmony. Behind the scenes, though, it would evangelise Dash among web developers and browser makers and push for standardisation "and adoption across the board".

The memo leaked as Google revealed Dart at the Goto Conference in 2011.

Bak says Dart makes programmers more efficient for the web and notes that neither he, nor Google, has "a problem" with JavaScript. He points to his history on V8 as proof of his commitment - and Google's - to the language.

"This is not taking anything away from JavaScript... we have to make sure the web really competes well. With the mobile ecosystem we have to do a lot of innovation in the browser," Bak says. "I have no problems with JavaScript."

He does have a point: V8 helped push browser-makers in to competing on JavaScript rendering speeds, producing a battle of the benchmarks between 2009 and 2011 so tech companies could all claim to have the "fastest" browser on the web. Today, JavaScript is running faster in the browser than at any time.

V8 helped change the web development strategy of the world’s largest software company – Microsoft. As Mozilla and the WebKit team were working to become the fastest JavaScript engines on the web and Microsoft risked being branded the web's slowest browser, the kiss of death among devs who are the gatekeepers to what gets built and used in software.

C++ or ColdFusion - Dart's future

When Microsoft released IE9, it dumped more than a decade of history of forcing devs to build one version of their sites for Microsoft's browser and another version for everybody else. For its new browser, Redmond went with a standards-compliant and streamlined JavaScript engine, Chakra. Chakra helped Microsoft run that benchmark race.

Fate is a shifting force in programming languages. C++, Java and PHP are today riding high, but for how long? Others that were once big - such as ColdFusion from Macromedia and Adobe for rapid web application development - are now in terminal decline.

JavaScript was standardised as ECMAScript in 1997 - as ColdFusion was on the rise - but it was only within the last half decade that it come into its own. This is because devs were finally recognising JavaScript's power as a client-side language that came with the familiarity of C and Java, but without the problem - thanks to the ECMAScript standard - of being tied in to a single vendor's runtime or roadmap.

Now, there are moves afoot to extend it further on the server with Node.js.

Bak is confident Dart has a long future at the top and feels working for the internet's largest search and ad company will help propel it. Yet Dart must gain credibility inside and outside the Googleplex. It also remains in desperate need of a finished VM: the "snapshotting" that would allow Dart to spin up services such as Gmail more quickly than can be done in JavaScript is dependent upon the shiny new VM.

But, as we know, VMs are Bak's territory; it's languages that are tricky.

“Most people talk of a long adopt period – more than five years. We have working on this for two years and we already have good community. It looks pretty good, I’m very optimistic right now,“ Bak says. “This [Google] is the right place to do these projects.” ®