Thursday, March 28, 2024

What Does the Google Dart Programming Language Mean for Web Developers?

In October, 2011, Google introduced its Dart programming language to developers. Dart is Google’s solution to the problems inherint in the JavaScript scripting language, with an obstensive goal that said to be to “ultimately to replace JavaScript as the lingua franca of web development on the open web platform.” So what does this new web programming language mean for web developers? In this article we will look at Dart, discuss its merits and let you know what you can expect from this new language.

Along with Google’s announcement about Dart, they also announced the debut of a website that is devoted to the language, appropriately called DartLang.org. The site features the Dart language specification, library reference, a Getting Started Guide, code samples, articles and discussion.

DartLang.org

So What’s Wrong With JavaScript?

The problems with JavaScript, as Google sees it, is not something that can be solved by just evolving the language. The biggest issues with JavaScript are a lack of high level security, and an inability to be (re)tooled for large scale projects.

Often developers create a JavaScript app which starts out small, but quickly grows to gargantuan proportions, with no apparent structure, and without adequate documentation, these JavaScript apps quickly become hard to debug and maintain. Largely they are incredibly difficult to break into pieces so that development teams can work on them without stepping on each others toes. Dart was designed to solve that problem.

Another issue with current scripting languages, JavaScript included, is that they do not allow developers to use both static and dynamic methodology. Such languages often include the use of heavyweight toolchains, and using them can make the developer feel stuck with very few options.

Key Features of Dart

The Dart language, like any programming language, has certain key features that make it useful for particular applications. Among Dart’s features are:

  • Classes – Dart’s clases and interfaces give developers what they need to effectively understand how to define APIs, and the constructs allow the encapsulation and reuse of data and methods.
  • Optional Types – Unlike JavaScript, Dart allows developers to optionally add static types to the applications. Dart is very extensible, enabling the migration of an app from just a basic, untyped prototype to an extremely complex, modular app using types, which state the intent of the programmer using less documentation than JavaScript typically requires.
  • Libraries – The libraries used by Dart will not change during runtime–it’s something that’s guaranteed inherintly by the language. Pieces of Dart code that are independently developed are thus able to rely upon those shared libraries.
  • Tooling – Although the Dart language is still in its infancy and tools are still limited, Dart will include an extensive set of execution environments, libraries and tools that are designed exclusively for the language. One rumor is that Google will be providing a full-fledge Dart integrated development environment (IDE) which will include the ability to create and test Dart applications on-the-fly.

Instead of requiring browser makers to add Dart functionality into their browsers, Google has created Dart so that it compiles the Dart code into ECMAScript 3 (aka JavaScript) so that non-Dart compatible browsers (i.e. any brother other than Chrome) can still utilize the Dart code.

Dart will use a new script MIME type, “application/dart,” and can be included within a web page using a #import or #source statement to reference external files. It will look like this:

<script type="application/dart">
...
</script>

What Does a Dart App Look Like?

The following Dart code, taken from Google’s DartLang.org website, shows a simple “Hello World” Dart application. Here is what the Dart code itself looks like:

// Copyright (c) 2011, the Dart project authors.  Please see the AUTHORS file 
// for details. All rights reserved. Use of this source code is governed by a 
// BSD-style license that can be found in the LICENSE file.  
#library('hi');  
#import('dart:html');  
main() {   
document.query('#status').innerHTML = 'Hi, Dart'; 
} 

And here’s the corresponding HTML code that goes with it:

<!-- Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file   
for details. All rights reserved. Use of this source code is governed by a   
BSD-style license that can be found in the LICENSE file. --> 
<html>  
  <head>   
   <title>Hi Dart</title>  
  </head>  
  <body>   
   <h2 id="status">dart is not running</h2>   
   <script type="application/dart" src="hi.dart"></script>  
  </body> 
</html> 

To actually compile the Dart code into usable code requires the use of a command line interface, building the dartc compiler, then, along with python, converting it into JavaScript, like this:

$ python ./client/tools/htmlconverter.py client/samples/hi/hi.html -o out/

Conclusion

As you can see, Dart has a huge potential to be another excellent tool in the web developer’s toolbox, but it’s not quite ready for primetime. Keep on eye on Google Dart, as you will definitely be seeing more about it over the next year.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Popular Articles

Featured