Google starts to detail Dart
Written by Ian Elliot   
Monday, 10 October 2011

Google has released an early preview of Dart. It is as revolutionary as we might have hoped for a JavaScript killer - or is it just another Java clone?

 

A while back, Google allowed it to be known that it was proposing a second new language in addition to Go. The Dart language was later revealed to be a JavaScript replacement. It seemed that Google had decided the JavaScript just wasn't up to the job of building the web apps of the future and had decided to work towards its replacement rather than improvement. Hence Dart: a language for structured web programming.

googledart

Now we have an early preview of Dart and there are no huge shocks - it's a class-based, object-oriented language. The design goals are stated as:

  • Create a structured yet flexible language for web programming.
  • Make Dart feel familiar and natural to programmers and thus easy to learn.
  • Ensure that Dart delivers high performance on all modern web browsers and environments ranging from small handheld devices to server-side execution.

The only controversial aim is "familiar and natural" because it all depends on what you consider to be familiar and natural. JavaScript isn't class-based and this tends to annoy and confuse programmers brought up in the class-based language tradition of C++, Java and C#, say. It doesn't however mean that a non-class based approach is necessarily wrong for the web or for a dynamic language.

Class-based languages generally impose strong typing, but such is the need to balance ease of use and dynamic aspects of the language that Dart is optionally typed. That is, you can start off with no typing and add it later. This, of course, makes little sense; the problem of sorting out type after the event is much more than enforcing it from the start. It leads to much more work than simply ignoring type and going typeless. A class-based language has a natural type hierarchy; a non-class-based language has about as much use for type as a fish has for a bicycle.

It is also interesting to note what is missing. Functions are just functions and not objects and the language is single threaded. There are no namespace or modules and nothing much to aid large scale program development other than optional typing.

From the implementation point of view, Dart has an interpreted VM mode and a compiled mode. In this case the twist is that the compiler targets JavaScript as the final code so Dart is just another language using JavaScript as its machine code. This does however have the advantage of making it run on any existing browser, but it hardly makes it a JavaScript killer - it simply elevates it to the role of the "native" language for browsers. The VM mode of implementation seems to be reserved for server side execution and this at least reveals that the intention is to have a single language for both client and server.

googledart

As far as Dart goes, there seems to be nothing new. It is just the same old class-based, object-oriented language with optional typing to make it easier for beginners. You might as well just port Java, C++ or C# to do the job as invent a new language.

Here is a hello world in Dart:

main() {
print('Hello Dart World');
}

And here is a simple, typed, class definition and use:

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()); }

Notice the use of => as a shortcut to defining a function.

More Information

Dart: a language for structured web programming

Dart

dartlang.org

Goto conference

Newspeak

 

If you would like to be informed about new articles on I Programmer you can either follow us on Twitter or Facebook or you can subscribe to our weekly newsletter.

 

Banner


Chainguard Joins Docker Verified Publisher Program
15/03/2024

Chainguard has joined the Docker Verified Publisher (DVP) program, meaning its Chainguard Developer Images are now officially available on Docker's container image registry.



Android Studio Iguana With Crash Reports
05/03/2024

Google has announced that the latest version of Android Studio, Iguana, is now stable. It has version control system support in App Quality Insights and new built-in support for creating baseline prof [ ... ]


More News

Last Updated ( Monday, 10 October 2011 )