Dart, a Java alternative for smartphone apps

Dart allows you to create multi-platform applications with the syntax of a very classic language.

This Google language is available at dart.dev. It can be used on Android instead of Java or on iOS.
It has real classes and implements competition in the form of communicating subjects with their environment .

Dart futur
The future is never what it was

Faced with fundamental design problems in JavaScript, which it considers untenable with progressive improvements, Google chose a radical solution: completely replace the language with another, with syntax that removes JS flaws. But JavaScript is actually an interesting language in its overall design, these are details that leave a lot to be desired, and Dart unfortunately also abandons this innovative design to return to the classics.

In the browser, there is another better solution - to allow the use of any programming language on the frontend to the bytecode - the role that WebAssembly currently performs.

Google promises that programming in Dart will become interactive thanks to the tools provided, we will be able to edit and run the program directly, as well as change the code based on the results. For a web application, this would be a huge advantage.
Programs can be evolutionary. This can start with a dynamic variable script, which can become an application where typed variables and classes are added.

Dart competed with SoundScript (also by Google), a JavaScript mode that supports typed variables and other features to improve performance, while removing JS flaws.

Google abandoned the introduction of the Dart virtual machine into the Chrome browser in 2015. But Dart can always be compiled in JavaScript as TypeScript. Google uses Angular 2 Dart for some of these internal projects, even if Angular runs TypeScript by default.

Dart allows you to make mobile apps for Android and iOS with Flutter as the interface, and is also the programming language of Android (or Fuchsia), Google's future OS designed for security, with Flutter as well. We will follow the development of this project.

Modern version C with classes

The syntax of the Dart language, created in 2011, is more than classical, it is very close to the syntax of C (1972) and JavaScript (1995). It can be defined as a simplified version of C++ .

The Dart program can be run by a virtual machine for a local or smartphone application (Dart Native) or compiled in JavaScript and thus create code that will be used by all browsers (Dart Web).

The syntax is very classic, if not ancient, close to JavaScript, created in the 90s and C, created by him in 1972. This classicism is deliberate. However, the proposed language provides very modern possibilities.

Dart vs TypeScript

Comparison of the syntax of two front-end candidates in JavaScript (there are others).

Show "Hello, world!."

Darth

void main() {
  print("Salut le Monde!");
}

TypeScript

function main() {
   console.log("Salut le Monde!");
}
Declare String. The TypeScript declaration adds an additional type.

Darth

String str = "Hello en Dart";

TypeScript

var str : string = "Hello en TypeScript";
The variable type can be determined by the output from the Dart declaration. In the case of TypeScript, this is a dynamic variable.

Darth

var str = "Hello en Dart";

TypeScript

var str = "Hello en TypeScript";
Combine two variables a and b... Dart repeats the PHP principle, which is more convenient in some cases.

Darth

String x = "$a$b"

TypeScript

var x = a + b;
If structure. Similar to JavaScript

Darth

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");
}
The structure of the Dart switch is similar to that of the JS with additional options. In Dart, each item must end with a break, continuity, trow, or return if it is not empty. In this case, it is combined with the next one. A similar effect can be exerted on a non-blank continuation article that performs a jump to the article if it has wording.

Darth

var x = "x";

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

TypeScript

var x = "x";

switch(x) {
  case "a": 
    console.log("a"); 
    break;
  case "b": 
  case "c": 
    console.log("b ou c"); 
    break;
  default:
    console.log("x");  
}
Loop for. Example for displaying string characters.

Darth

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... Ich. Works on collections as JS.

Darth

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)
  ...
}
Loop. Similar to JS.

Darth

int x;

while(true) {
  x++;
}

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

TypeScript

var x: number

while(true) {
  x++;
}

do {
  x++;
} while(true);
Function declaration. The function can have dynamic arguments, which is similar to multiple dispatch, but does not bring the same speed.

Darth

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

// On peut omettre le type.
add(a, b) {
  return(a + b);
}

TypeScript

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

// On peut omettre le type.
function add(a, b) {
  return(a + b);
}
Class and legacy. Both languages ​ ​ are simpler than JavaScript, but the Harmony implementation will give the latter the same capabilities. Both languages implement the interface, while Harmony offers abstractions with proxies.

Darth

class Vehicule {
  int carburant;
  int passagers;
  Vehicule(int this.vitesse, int this.passagers) {
  }
  int distance()   {
    return(this.carburant / this.passagers);
  }
}

class Voiture extends Vehicule {
   int puissance;
}

TypeScript

class Vehicule {
  carburant : number;
  passagers : number;
  constructor(vitesse : number, passagers : number) {
  }
  distance() {
    return(this.carburant / this.passagers);
  }
}

class Voiture extends Vehicule {
  puissance : number;
}
 

Both languages ​ ​ are similar and differ mainly in the inversion of the type and identifier for TypeScript - syntax dating back to the Pascal language! This syntax is used by Google for the Go language, which is 2 years before Dart.
Dart's capabilities are superior to TypeScript, but they are only compatible with the server version. And Dart compiled in JavaScript only works on recent browsers, not IE9, for example.

Dart and browsers, WebAssembly

There was a version of Chrome called Dartium that included a Dart virtual machine, but Microsoft and Apple did not want to integrate this language into their browser.
Apple is far from wanting to promote web applications, and the Webkit community has abandoned its implementation on the grounds that it is not included in web standards. The same is true of Mozilla, where it was believed that a future version of JavaScript could add the same improvements as Dart, in particular the class model and typed variables. We are not talking about Microsoft, which gave a negative review on this topic, besides, Microsoft chose another option with TypeScript.
Finally, even Google abandoned its implementation on Chrome in March 2015.

According to the authors, Dart will not compile in WebAssembly, which is rather a target for static languages ​ ​ like C or C++. This requires wasm to become the equivalent of JVM or CLR.

Why use Darth?

Dart's main drawback was tactical rather than technical order. Positioning himself as an alternative to JavaScript was his mistake. But after the decision (in March 2015) not to embed the virtual machine in the browser and, rather, compile only Dart in JavaScript, this drawback is now being removed.

This language is especially suitable for C and C++ regulars: the syntax is similar, although slightly modernized .
It can replace PHP or Node.js on the server and be compiled into JS for the browser, but for this second use it is probably best to use TypeScript.
It is especially suitable for creating applications on Android and iOS with the Flutter framework. This gives the advantage of one language across all platforms. Compared to React Native and Node on mobile devices, its advantage, in addition to speed, in related development tools.

Example script in Dart

First, download the zip archive to the site, and place the content 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 find yourself face to face with a large number of files that include a server that cannot be used without seriously studying the guide. First, it's easier to go through the command line. In the code editor, type:

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

Save the script in hello.dart in any directory, such as dart. The script is run with the command:

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

Hello World will show it!

If you want to continue with the language to add its path to the Windows PATH variable, you just need to enter dart to run the program.

To go further...

Toolbox

Documents and Resources

See also...

Programming and dated languages - Asm.js- - BASIC- C- -C++ # C- - Darth-Eiffel - Guo- --JavaJavaScript--Julia PascalPHP- - - Python- - Prolog RubyLa ScalaScriptolSwift TypeScriptHTMLVasmXMLXAML SQL