Change happens gradually. Google knew that back in 2010 when, frustrated with perceived fundamental flaws in JavaScript, it first decided to create Dart, a more structured yet flexible programming language.

JavaScript was and still is entrenched as a lingua franca of sorts in Web development, but after three years of buildup and open-source collaboration, Dart looks to redefine the programming landscape.

(Dart’s release: Google says Dart 1.0 is ready for wide Web use)

Dart 1.0 has been widely available since November, and its documentation and tools are completely open source. The question now is whether Dart is all it’s cracked up to be. Whether the language sees more widespread adoption or not depends on the effectiveness of its development tools and resources, and how Dart’s changes in structure, syntax and libraries stack up against JavaScript.

Going off-scriptWhy Google created Dart
Dart was designed to make it easy to write modern app-development tools capable of high-performance implementations. Formerly known as Dash, Dart is a class-based, object-oriented language with C-style syntax that also comes with a programming environment, a set of libraries and a virtual machine.

According to Google software engineer and Dart co-creator Lars Bak, the Dart project started two and a half years ago with two distinct goals: increased programmer productivity, and faster execution. And he believes Dart has achieved them.

“There’s a very fast turnaround cycle from when you change the source code until when you run the code,” Bak said. “In our case, if you use the VM, we changed the source code to program right away. If you’re used to Java or another programming language where you have to go through tools before you can run the program, in Dart you can run them right away.”

Lowering that source code runtime threshold leaves Dart free of what Bak called defensive programming. He explained that when dealing with a long tool chain, developers often fall into the habit of playing it safe. They spend an inordinate amount of time examining the code before compiling and running the program, instead of having the freedom to experiment with code.

(A leaked 2010 e-mail laying out Google’s Dart strategy)

Dart’s other overarching goal of faster execution is targeted specifically at the front end of browsers, spurred by longstanding frustrations with JavaScript’s shortcomings in writing larger Web applications.

Bak’s team created Dart with that goal in mind, equipping the language with more structure in the form of classes, mixins and interfaces, along with a system of libraries he believed will appeal to programmers writing larger bodies of code. While the syntax of Dart is largely familiar to JavaScript, he pointed out one particular feature called Optional Typing that lends itself to writing larger Web apps.

“When you start experimenting with a program, you can write code without types, and if you get closer to finalizing a module, you can put in types in the interface,” Bak explained. “So if our team members are using your interface, you can actually validate your code against that interface. So you can be experimental in the language but also harden it up and use types as a way of ensuring that people are only using the code in a certain way.”

While Dart’s improvements in executing larger applications paint it as an appealing option for modern Web development, JavaScript is far from an unchanging language. Thanks to the forthcoming update to JavaScript’s standardized form, ECMAScript, Dart has its work cut out for it. The update addresses many of Google’s criticisms of the widely adopted language, particularly in regards to writing larger, more complex applications.

ECMAScript 6, targeted for implementation in December of this year, is “really focused on scaling up JavaScript as a language to encompass the full range of what people are doing with it today, to develop complex applications and libraries,” said Allen Wirfs-Brock, Mozilla research fellow and project editor of the ECMAScript language.

“ECMAScript 6 takes JavaScript from the classic scripting language thinking of writing programs of a few hundred lines to do simple manipulations of resources, to a full-featured programming language capable of all sorts of complex features.”

Inside the Dart SDK and IDEs
Dart 1.0 carries a host of SDK tools, IDEs and VMs, each bringing its own Web development features and capabilities to the table. Bak delved into a few of the most important ones for programmers:

dart2js compiler: This tool inside the SDK translates Dart code into JavaScript. “This ensures that if you write a Dart program for a Web application, it can translate into JavaScript and it can run on all modern browsers,” Bak said. “We have no intention of fragmenting the Web.”

dartanalyzer: A static analyzer that verifies whether static type information in the program is correct. “This is something that’s a bit different from most other systems; even though you get warnings in the static analyzer, you can still run the program,” Bak said. “When we run Dart, we don’t use the static type information for anything other than helping the programmer see where there are problems in their code.”

Dart standalone VM: A virtual machine with a built-in dynamic compiler that generates code for both 32- and 64-bit CPU architectures to better support server-side execution of Dart. “We would like to expand the VM so that people doing Web applications can also have [front-end] and server code written in Dart,” Bak said. “Then you can have the same modules being used on the client-side but also on the server-side.”

Eclipse IDE: A slimmed-down version of Eclipse as the main Dart IDE. “It has incremental checking of your code, and you have a button to run it right away, and that makes it very easy to get up and running right away,” Bak said. “If you have a background in JavaScript or ActionScript or C#, it’s very simple to pick up. It should take an hour, and you can use Dart.”

Dartium: A special build of the Chromium source base integrated with the Dart VM, a step toward building the language directly into Chrome. “When you’re doing development in the Chromium IDE, you change a few lines of code and run it right away without translating it first into JavaScript,” Bak said.

Spark IDE: A Chrome-based online IDE and toolkit, still in its very early stages. “Imagine you’re sitting with your Chrome OS machine and want to start development right in the browser,” Bak said. “Having a Web-based IDE is certainly very exciting, but again we’re just taking the first baby steps in that area.”

The history of ECMAScript
ECMAScript is managed under the control of Ecma International, a worldwide nonprofit standards organization. Within Ecma, the group that works on ECMAScript is known as TC39. Its members are the largely browsers and companies using JavaScript in large-scale Web implementations. For instance, the bi-monthly TC39 meetings take place at the headquarters of companies such as Yahoo, Microsoft, Mozilla, PayPal, and, as Wirfs-Brock pointed out, Google.

“Google is an active participant in TC39,” Wirfs-Brock said. “Within TC39, our job is the evolution of ECMAScript. However we got there—and sometimes what causes a technology to become a dominant or core technology is a set of coincidences—but ECMAScript is the language based into every browser. We see ourselves as stewards of that technology doing the job that needs to be done.”

JavaScript was first standardized into ECMAScript in 1996, and between then and 1999, three subsequent versions established the baseline of JavaScript or ECMAScript as it currently exists in browsers. In 2009, after a 10-year period without any official updates, ECMAScript 5 was released, though according to Wirfs-Brock, it was a set of relatively minor additions and clarifications addressing interoperability issues that emerged in 2006 and 2007.

TC39 is now in the latter stages of the next edition, ECMAScript 6, which is the first major enhancement to the language since 1999. The feature set is complete, and throughout the majority of 2014 the specification will be reviewed, validated, tested and implemented, with a target date of December 2014.

Dart vs. JavaScript
Software engineers and programmers working on Dart don’t shy away from the fact that the language was created and developed for the express purpose of improving upon and ultimately competing against JavaScript in the Web application space. Bak explained precisely which areas he thinks Dart’s performance, structure and functionality improve upon JavaScript’s limitations.

“We have, in designing the language, made the optic model of the language very simple; it allows us to get even better performance than JavaScript,” Bak said. “The faster you make the virtual machine, the more logic people can put on top of it, so this was a key goal when we started the project.”

Before cofounding Dart, Bak worked on Google’s V8 project (the JavaScript engine inside Chrome), and he has worked with virtual machines since 1986. In working closely with JavaScript, he found certain limitations that make it difficult to speed up virtual machines, which in his experience fixes a variety of issues.

Dart

“Before Dart, you would find companies like Google adding additions to JavaScript where they put types and comments, and try to make some checking anyways,” Bak said. “I think Dart is mostly a formalization of that, so this type-checking is built into the language. This is nice because when you get that extra headroom while writing applications, you can put more logic into your application without being penalized with slowness.”

In contrasting Dart’s mandates of speed and performance, Mozilla’s Wirfs-Brock talked about how JavaScript’s own optimized performance has contributed to its wide browser adoption, resulting in other languages translating into JavaScript.

“Performance has gotten so good that one of the phenomena we’ve seen with JavaScript—since it’s the only language built with all browsers—is people are now taking other languages with existing code to run in the browser and compiling it into JavaScript code,” said Wirfs-Brock. “Performances of JavaScript engines across the board are such that you can now take, say, C++ code through this compilation process, run it and get performance good enough for usable implementations of native JavaScript codebases.”

The chief goal of ECMAScript 6 is bringing that speed and performance to the creation of the larger applications becoming more and more prevalent on the Web. Wirfs-Brock said this comes down to making the programmer’s life easier, and ECMAScript 6 uses a number of syntactic enhancements to make the language more concise to express it in fewer lines of code.

“We’ve added more concise ways to write functions, better support for optional arguments, and variable number of arguments,” he said. “The most important way we’ve achieved this is the addition of class syntax. JavaScript hasn’t had a single syntactic way to define the concept of class until now. By enabling programmers to say things more concisely, it reduces overall complexity of items they need to deal with at any one time.”

Wirfs-Brock made one other major point in enabling JavaScript’s ability to handle more-complex applications: ECMAScript 6’s modules. The modules separate the functionality of a program into independent, interchangeable executable aspects.

“Modularizing a large program into independent pieces where you explicitly identify how the pieces interact creates a building block-style approach,” Wirfs-Brock said. “Rather than deal with a single program of 100,000 lines, you would deal with 20 modules of 5,000 lines.”

Another area in JavaScript the Dart team set out to improve was startup. Dart adopted a system called Snapshot, previously used in languages such as Lisp and Smalltalk, which helps applications start quickly by taking the source code off an app and generating a binary format.

“When you load in a Web application in JavaScript today, you’re often loading in source code, and before you can start running you need to parse all that code,” Bak explained. “Sometimes if you’re running on low-end devices like mobile phones, there’s a lag time before you can get the application started. Snapshot is basically a serialized form of the heap [tree-based data structure].”

Ultimately, though, Bak sees Dart’s clean, simple semantics as the biggest draw over JavaScript. The language is structured with abstraction mechanisms for writing larger applications, and Dart’s libraries can’t be changed on the fly, unlike in JavaScript where it’s common to load in various libraries that perform monkey patching, which is extending or modifying the runtime code without altering the source code.

“Dart is very easy to start using because there’s nothing really mind-blowing in the language except for the optional typing, and the libraries you load in work exactly the same way as the last time you used them,” Bak said. “The fact that we have optional typing means that two teams working on two separate parts of the project can state their intent with types in the interface so the other team can check against it. It makes a huge difference that’s not possible in JavaScript.”

In place of changing the program while it runs, Dart uses tree shaking, a pre-deployment step that eliminates unused classes and methods to reduce download times and improve startup times.

“We can do static analysis of the program, and throughout the code we can prove that’s not being used, and then only emit that to the deployed version of the program,” Bak said. “When you write your program, you can include all your libraries in the program you want, and you’re not penalized for a big library if you don’t use all of it.”

The ECMAScript 6 implementation is designed to shore up some of JavaScript’s shortcomings in this area, particularly in terms of libraries, modules, and features such as proxies. Wirfs-Brock laid out some of the major changes in syntax and libraries.

“The language now has full capabilities that enable the writer to fully write the libraries in ECMAScript itself,” he said. “When JavaScript was originally introduced, libraries were all implemented in another language, most importantly the DOM browser library. What we’ve done in terms of access to binary data and the processing model that can be used to describe libraries is make sure complex libraries can be implemented in JavaScript itself.”

Wirfs-Brock also talked about the addition of proxies in the same modular sense, a means in the language to control how individual objects behave more at the level of native code, but express it at the level of JavaScript.

“Traditionally, JavaScript libraries are simply accessed on an HTML page having script block in HTML instead of inline JavaScript code that references files somewhere on the Web,” Wirfs-Brock said. “Modularity support allows you to take a library and wrap it as a module. This is really important in app development now. Large apps based on third-party libraries will be able to combine [the] use of libraries [coming] from different sources without interfering with each other.”

Rewriting the rules of Web development
Going forward, Bak said the “Holy Grail” for him is to see Dart ignite a wave of more complex Web applications. More than a decade ago, the industry changed around JavaScript execution, and Google is positioning Dart in the same vein: a platform whose advances in productivity and performance will drive adoption in mainstream browsers.

“Performance solves everything, so when we can demonstrate that Dart programs run much faster than JavaScript programs, that’s a clear incentive to have that runtime system in the browsers,” Bak said.

In the next year, Dart’s formal specification will likely be ratified by Ecma, and in the short term the Dart team is working to fix bugs and keep the library stable to ensure backward compatibility. Other goals for the year include improvements to the VM, changes to the dart2js translator to make it faster and smaller, and improving the tool chain for better debugging and deployment support from within the IDE.

(Dart on track to become an Ecma standard programming language)

“If you look over the last four years on the Web, you’ll see that Web applications have been using more and more libraries,” Bak said. “In fact, applications are just getting bigger and bigger. I think a language like Dart that has more structured access to help take that to the next level in terms of complexity. There’s no way around it, you’ll see more and more logic, code running in the browser.”

Looking toward Dart’s goal of attaining widespread adoption across major browsers, Wirfs-Brock believed the language is taking the long way around. He pointed to CoffeeScript or Microsoft’s TypeScript as languages built as a layer on top of JavaScript, instead of building the language into the base layers of the Web as Dart is doing.

Going off-script“There are two paths someone developing a language might take. The strategy of having a language work on top of JavaScript is an easier in,” Wirfs-Brock said. “Building a language and using JavaScript as a hosting environment and virtual machine, all you need to do is get people interested. Trying to bypass and get new languages built into base layers of a Web platform is a much harder path to take, since everyone who creates major browser frameworks needs to decide to adopt that technology. It’s a pretty high bar to set.”

Putting aside the current atmosphere of competition between Dart and JavaScript in the Web development space, Wirfs-Brock believed JavaScript has reached a level of dominance that keeps it out of jeopardy.

“I think if somebody looks back 30 years from now, they’ll think JavaScript was the dominant programming language over that period of time,” he said. “I feel pretty comfortable making that prediction. In many ways, as we go into the post-PC era of computing, JavaScript is positioned the way C was in the early 1980s as the foundation of everything. While there’ll always be many languages, we’re at the point where JavaScript is the language everybody has to know.”

Despite that uphill battle for wider use and mainstream browser adoption, Dart’s development is guided by an open-source philosophy, which has driven community engagement with the platform from the inception of the language.

Goals such as extracting and wide-releasing services from within the Eclipse IDE give developers license to use Dart any way they want, resulting in plug-ins like the JetBrains IDE, as well as early deployments in places like Mixbook, a scrapbooking software company. Bak believes if you simply give programmers the freedom of access, they’ll take the innovation from there.

“Back when I was working on V8, we came out with the beta version of Chrome,” Bak said. “That kind of performance boost in the platform gets programmers doing really creative and crazy things. They’ll start experimenting with more code in the client, and I think we can get that same boost with Dart, taking it to the next level. So I really hope we rewrite the way you can create programs for the Web.”