(T) Over the last few months, a few Google engineers have been presented Dart an open-source Web programming language started at Google in many meetings in Silicon Valley. Dart aims to be another option to JavaScript for writing scripts embedded in Web client applications. Dart’s goals according to Google are to provide a structured yet flexible Web programming language, for all types of Web devices, running across all major browsers while still providing the syntax and tools familiar to developers.
Dart is an object-oriented language (class-based, single inheritance) and leverages a C-style syntax. It supports interfaces, abstract classes, and reified generics. One of the key features of Dart is its optional support of static types in the code. Static type annotations can provide clear documentation of the code, while type-checking tools can be used for debugging. Programmers can migrate an untyped prototype to a higher performance application with typing.
Dart applications are designed and launched using the Dart Editor based on Eclipse, and run within a virtual machine within the browser for Google’s Chrome or compiled into JavaScript to run in Microsoft’s IE, Mozilla’s Firefox and Apple’s Safari.
As an open source project, the success of Dart will depend on its adoption in commercial products which will require that the Dart VM is supported natively in the major browsers from Apple, Microsoft and Mozilla, a major challenge to overcome.
Code Examples
Defining an interface:
interface Shape { num perimeter();
}
class Rectangle implements Shape {
final num height, width;
Rectangle(num this.height, num this.width); // Compact constructor syntax. num perimeter() => 2*height + 2*width; // Short function syntax.
}
class Square extends Rectangle { Square(num size) : super(size, size);
}
Untyped Code that create a new class “Point” with two parameters x and y, and two methods: scale () and distance ():
Class Point {
var x, y;
Point(this.x, this.y);
scale(factor) => new Point(x*factor, y*factor); distance() => Math.sqrt(x*x + y*y);
}
main() {
var a = new Point(2,3).scale(10); print(a.distance());
}
Typed code that ensures that x,y, and factor are of type num, and that a Point contains two values of type num:
Class Point {
num x, y;
Point(num this.x, num this.y);
Point scale(num factor) => new Point(x*factor, y*factor); num distance() => Math.sqrt(x*x + y*y);
}
void main() {
Point a = new Point(2,3).scale(10); print(a.distance());
}
Link from an HTML page to a Dart program. Here is the proposed new MIME type, “application/dart”:
<!DOCTYPE html>
<html>
<head>
<title>Simple Dart Web App</title> </head>
<body>
<h1>Simple Dart Web App</h1>
<h2 id=”status”>dart is starting up…</h2>
http://SimpleDartWebApp.dart http://a%20title=
</body>
</html>
var x, y;
Point(this.x, this.y);
scale(factor) => new Point(x*factor, y*factor); distance() => Math.sqrt(x*x + y*y);
}
main() {
var a = new Point(2,3).scale(10); print(a.distance());
}
References
www.dartlang.org
Google Blog
Copyright © 2005-2012 by Serge-Paul Carrasco. All rights reserved.
Contact Us: asvinsider at gmail dot com.
Categories: Development Tools, Front-End, Web