Dart, successor to C++ for modern apps

Dart runs in the browser and on the server, it provides the features of a very classical application programming language.

The new language from Google is available at dartlang.org, it offers a front-end to JavaScript in the browser or an alternative to Node.js on the server.
It implements concurrency in the form of communicating actors with their own environment and has true classes.

Dart futur
The future remains what it was

Faced with fundamental design problems in JavaScript that it see not solved by incremental improvements, Google opted for a radical solution: completely replaces the language with another, with a syntax that is between that of JavaScript and Java. But JavaScript is a language that is interesting in its overall design, it is the details that are weak and Dart unfortunately change this innovative design to return to the classics.

Another solution would have beem better: to allow browsers to use any programming language. Or use a bytecode for which we could create different languages ​​in frontend (a role fulfilled actually by Asm.js).

Google promises that programming in Dart will become interactive thanks to tools, you will edit and run a program directly, and change the code according to the results. For a Web application, it will be a big advantage.
Programs may be evolving. You can begin with a simple script with dynamic variables, which can be transformed into application when you add typed variables and classes.
Another advantage is the ability to use the same language on the server and the browser, which simplifies programming, but we can already do that with Node.js (and the Google's V8 compiler).

Dart now competes with SoundScript (from Google too) a JavaScript mode that brings typed variables and other features that increase performances, these two things making void JS disadvantages that led to the creation of Dart.

On March 25, 2015, Google announced that it would not implement the Dart VM in Chrome browser: Dart is compiled into JavaScript client side (like TypeScript) or possibly runs on the Dart VM server side.

A modern version of C with classes to replace JavaScript

The syntax of Dart in 2011 is more than classic, it's actually that of languages of the 70. Python in 1991 or the Scriptol language in 2001 were already more innovative.

A Dart program can be executed by a virtual machine or compiled into JavaScript and thus produce a code usable by all browsers.

There is really nothing innovative in the syntax, nothing but a kind of upgrading for JavaScript - a language created in the 90 - to the norms of yesterday, or a modern version of C - created in 1972. The language offers powerful features, but its design really lacks imagination.
Dart is interesting as the successor of C to make scripts (not as system language), but why it was thought that a 40 years old language is the best model to make modern Web applications is beyond comprehension.

Dart vs. TypeScript

Comparison of the syntax of the two candidates to be used in frontend to JavaScript (there are other alternatives).

Displaying "Hello World!".

Dart

void main()
{
  print("Hello World!");
}

TypeScript

function main()
{
   console.log("Hello World!");
}
Declaring a string. TypeScript adds the type in option.

Dart

String str = "Hello in Dart";

TypeScript

var str : string = "Hello in TypeScript";
The type of a variable can be determined by inference in Dart. In the case of TypeScript it is a dynamic variable.

Dart

var str = "Hello in Dart";

TypeScript

var str = "Hello in TypeScript";
Concatenate two variables a and b... Dart uses the principle of PHP which is more convenient in some cases.

Dart

String x = "$a$b"

TypeScript

var x = a + b;
if. Similar to JavaScript

Dart

if (x == 1) 
{
  print("1");
} else if(x == 2) {
  print("2");
} else {
  print("x");
}

TypeScript

if (x == 1) 
{
  console.log("1");
} else if(x == 2) {
  console.log("2");
} else {
  console.log("x");
}
switch in Dart is similar to JS with more options. Each rule must be terminated by break, continue, throw ou return but if it is empty. In this cas it falls through the following. You can have a similar effect on a non-empty clause with continuous that performs a jump on another rule if it has a label.

Dart

var x = "x";

switch(x) {
  case "a": 
    print("a"); 
    break;
  case "b": 
  case "c": 
    print("b or c"); 
    break;
  default:
    print("x");  
}

TypeScript

var x = "x";

switch(x) {
  case "a": 
    console.log("a"); 
    break;
  case "b": 
    console.log("b"); 
  case "c": 
    console.log("b or c"); 
    break;
  default:
    console.log("x");  
}
for loop. Example to display the chars in a string.

Dart

var str = "demo";
for(var i = 0; i < str.length; i++) {
  print(str[i]);
}

TypeScript

var str = "demo";
for(var i = 0; i < str.length; i++) {
  console.log(str[i]);
}
For ... each. Works on collections like in JS.

Dart

var arr = [ 1,2,3 ];
for(var x in arr) {
  print(x);
}

TypeScript

var arr = [ 1,2,3 ];
for(var x in arr) {
  console.log(x)
  ...
}
while loop. Like JavaScript.

Dart

int x;

while(true) {
  x++;
}

do {
  x++;
} while(true);

TypeScript

var x: number

while(true) {
  x++;
}

do {
  x++;
} while(true);
Declaration of a function. A function can have dynamic arguments, which is similar to multiple dispatch, but does not provide the same speed.

Dart

String catstr(String str)  {
  String x = "Message : $str";
  return x;
}
print(catstr("Hello"));

// The type may be omitted.
add(a, b) {
  return(a + b);
}

TypeScript

function catstr(str : string) : String {
  var x : string = "Message : $str";
  return x;
}
console.log(catstr("Hello"));

// The type may be omitted.
function add(a, b) {
  return(a + b);
}
Class and inheritance. Both languages ​​are simpler than JavaScript, but the Harmony implementation offer the same features. Both implement interfaces, while Harmony offers abstractions through proxies.

Dart

class Vehicle {
  int fuel ;
  int passengers;
  Vehicle(int this.speed, int this.passengers) {
  }
  int distance()   {
    return(this.fuel  / this.passengers);
  }
}

class Car extends Vehicle {
   int power;
}

TypeScript

class Vehicle
{
  fuel : number;
  passengers : number;
  constructor(speed : number, passengers : number) {
  }
  distance()
  {
    return(this.fuel  / this.passengers);
  }
}

class Car extends Vehicle
{
  power : number;
}
 

The languages ​​are similar and differ mainly by reversing the type and the identifier for TypeScript, a syntax that dates back to the Pascal language! This syntax is used by Google for the Go language that is 2 years older than Dart.
Dart has also other features not in TypeScript, but they are available only when compiled to binary.

Dart will it be supported on all browsers?

It is unlikely that Microsoft or Apple adopt this language before a long time, so the virtual machine was confined to Chromium. In fact Microsoft chose a different option: to develop TypeScript, a language that is compiled to JavaScript.
In fact, even Google renounced to implement it in its browser.

There was a version of Chrome which integrates a Dart virtual machine called Dartium. However, the community that develops Webkit refused its implementation on the ground that is not part of the standard Web. It's the same thing on the side of Mozilla where one believes that a future version of JavaScript could add the same improvements that brings Dart, mainly the class model and typed variables (without losing the advantages of JavaScript). We do not mean that Microsoft has issued a negative opinion on the subject, or that Apple is far from wanting to support Google.

Why use Dart?

The main shortcoming of Dart was tactical and not technical. Positioning itself as an alternative to JavaScript was its mistake. But after the decision (March 2015) to not implement the virtual machine on the browser and instead just compile Dart to JavaScript, this issue is now removed. (Ref).

This language is particularly suited to those familiar with C and C++: the syntax is absolutely identical, although somewhat modernized.
It can replace Node.js or PHP on the server and be compiled to JS for the browser, but TypeScript is probably better for this second use. It is a language for scripting and possibly to make applications on Android.
Its main advantage over Phonegap and Node.is (besides speed) is in its development tools, although Visual Studio Code recently offered by Microsoft on all platforms, partially offsets it.

Getting started with the language

To begin, download the zip archive from the site, and extract the contents in a directory, for example c:\dart (it only works on Windows).

You can launch the Dart editor and create a project, but then you are faced with a lot of files including a server, that you can't use without having seriously studied the manual.
To start simply we go through the command line instead. In a code editor, type:

main() {
  print("Hello World!");
}

Save the script in the hello.dart file in any directory, for example that of dart. The script is launched with the command:

c:\dart\dart-sdk\bin\dart hello.dart

This will display Hello World!

It will be necessary if you want to continue with the language to add its path to the Windows PATH variable, then you have simply to type dart to start a program.

Going further...

Tools

Documents and resources

See also...

Programming and data languages Asm.js - Basic - C - C++ - C# - Dart - Eiffel - Go - Java - JavaScript - Julia - Pascal - PHP - Python - Ruby - Rust - Scala - Scriptol - TypeScript - HTML - Wasm - XML - XAML - SQL