< Google Chrome: A Web Developer's Take
Oct 18, 2011 at 12:05am
Age: 13 yrs
Category: Web Technology
By: Steven Holms

Google Dart: A New Language for the Web


Google Dart logo

Google Dart logo

Here at Rapidfyre in Walla Walla, we like to keep up with the latest tech news. Just over a week  ago, Opens external link in new windowGoogle released a developer preview of their new Opens external link in new windowprogramming language for the web: Opens external link in new windowDart. Dart is an interesting project. It is Opens external link in new windowopen source, and is meant to replace Opens external link in new windowJavaScript for building we applications. Its syntax is much more C or Java like than JavaScript, and it has some interesting Opens external link in new windowobject-oriented concepts. While I am still just scratching the surface of what Dart is and what it can do for web developers, I thought I’d share some first impressions.

Dart as a JavaScript Replacement

First of all, Dart solves several major issues with JavaScript. For those who have used JavaScript, you probably know that JavaScript lacks a normal Opens external link in new windowclass-based object-oriented style. While its object-oriented functions are quite good and easy to use once you learn them, they are much different from traditional languages’ implementations, and the lack of a true class structure is annoying in a lot of web application development. Dart comes with classes, and actually relies heavily on them.

Its all about the DOM

Another major issue that Dart solves is JavaScript’s painful Opens external link in new windowDOM API. Many web developers, including us here at Rapidfyre, use Opens external link in new windowjQuery to make interacting with the DOM (or Document Object Model) more efficient. JavaScript has some good built in DOM support in all browsers, but it is quite unwieldy. For example, to do a simple selection of an element based on its id, you would use: 

 

document.getElementById(‘<id name>’)

 

 

This is a lot of effort, and it only gets worse the more you try to do with JavaScript's DOM API. With Dart, all that changes. Dart comes with a DOM library which makes selecting various DOM objects a breeze. Not only does Dart shorten the calls, but also streamlines how they are done. Here is the above example written in Dart:

 

document.query('<id name>')

 

In the previous example you wouldn't actually call document, you would call whatever object you created for interacting with the DOM. Another big deal in Dart's DOM library is that there are only two methods needed to select any DOM element: query() and queryAll()

JavaScript on the other hand uses a seperate method for each action, such as getElementsByClass(). Of course, there is a lot more in the DOM library, so be sure to read up on it at www.dartlang.org/articles/improving-the-dom/.

Beyond the DOM, Dart has several other major improvements to web programming. Among them is optional typing. In C++ and other traditional languages, you have to specify exactly what type of variable you are using (such as int for an integer, float for floating point, char for character, etc.), while in JavaScript you use the type var. Dart has the flexibility of JavaScript (allowing you to use var for all of your variables), and the control and verbosity of more traditional languages (Dart supports int, float, num, string, etc).

Running Dart

Dart is a Opens external link in new windowcompiled language, though not really in the traditional sense for now. Currently, Dart is compiled to JavaScript, and as such will run in most Opens external link in new windowmodern browsers. Google has also built a Opens external link in new windowvirtual machine for running compiled Dart code, but currently it’s being used server side, since no browsers are currently shipping it (though Opens external link in new windowChrome may get it in the coming months). So for now, don’t expect any advantage over JavaScript in performance. Until the virtual machine is integrated into a browser, Dart won’t really replace JavaScript, just enhance it. The nice thing is you won’t have to include a separate library like jQuery, since Dart already has an amazing selection engine, among other usually library oriented tasks. (Though there are ways to integrate JavaScript libraries into Dart if you really wanted to). The biggest downside is that when you compile to JavaScript, you are also compiling any necessary Dart libraries, which means that the application script has a lot of extra overhead. This should be negated by the fact that you no longer need separate libraries, so hopefully in the future, it will actually turn out to be more streamlined than a JavaScript equivalent.

Some hidden treats

For the past week, I’ve been working with the Dart Opens external link in new windowsource code. While I haven’t gotten a lot done as far as actually testing the language, I was able to successfully build all the components, including the virtual machine. I’m still looking for an easy way to use the virtual machine instead of JavaScript when compiling, but for now, the virtual machine isn’t the best way to develop in Dart anyway. While sifting through the source, I did come across a rudimentary code editor, based on the Opens external link in new windowEclipse IDE. It’s still a very rough project, and it took a lot of work to Opens external link in new windowcompile it, but its a great start on an editor. It supports basic code highlighting and error checking for Dart, and you can set up an HTML file and then run it in your browser.

Where it stands

Dart is definitely an interesting language, and it is positioned to be a real help to web application developers and the open web in general. There is still a lot of work that needs to be done before it can be considered for serious development, but the foundation looks good, and if it can get standardized and added into all browsers, it could really take off. In the mean time, we here at Rapidfyre will continue to use JavaScript, but will be keeping up with the evolution of Dart. I've included links to the Dart language homepage, as well as the Google Code page, where you can download the source and start using it.


Oops, an error occurred! Code: 20241210150429694a9807
©2024 Rapidfyre Inc, Web Design & Web Development  •  34 Quail Haven Ln, Tonasket, WA 98855  •  (509) 684-0600