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 .

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 main function executes the code after loading, and not as the page is parsed, as in JavaScript.
- Classes and interfaces.
Unlike JavaScript (before ECMAScript 6), Dart allows classes to be declared and has simple inheritance. It does not allow overloading methods . - Functions.
The function declares itself as in C (not with the function keyword, as in JavaScript), except that the return type is optional. If it is not specified, it is dynamic.
As in JavaScript, functions can be embedded in other functions . - Additional types.
The programmer can use dynamic variables for the script or variables typed for security in a larger project or for faster execution speed. - Asynchronous. You can start asynchronous operations with an avate or promises, which here are called "Future."
- Competitor.
Objects named Isolates can operate in a competitive environment. They transmit a message but have clear memory space.
So the language is not multithreaded, but has parallel processes, types of actors.
The + - symbol is used for addition or concatenation. It can also be overloaded with cool methods.
- Simplified auto-documentation.
- As in Script, the name should not be declared locally in the block when it already exists in the container block (here we get a warning, in Script it is a syntax error).
- The object is public (can be used outside the library) or private, in which case it is indicated by an underscore. In
- classes can be getters and setters. Syntax:
name type => expression. - The method can be static. After that, it is declared with the static prefix. The same goes for the attribute .
- Operators are JavaScript operators. This includes = = and! = = for strict comparisons .
- As in PHP, you can integrate variables into character strings with the prefix $.
- Reserved words:
abstraction, assett, asynchronous, await, case, catch, class, continued, to, exception, extends, factory, false, for, future, get, if, import, in, include, is, library, negate, operator, proxy, set, source, static, switch, throw, try, true, typedef, until, while - List of preset types and objects:
bool, Date, double, Duration, int, list, map, num, Isolate, Object, Math, Pattern, Queue, RegExp, String, var, void. - Mixin
A class that can be included in another class to form a composite object. Unlike the simple inheritance here, and not the multiple, several mixins can be included in one class (see dictionary). - Snapshot.
A snapshot is a form of program state persistence. Its data is written to the hard disk for use in the next session. This allows you to instantly restart the program as if it were in standby mode. (Current documentation does not mention this, but the snapshot code is part of the virtual machine code). - Streams.
Functional reactive programming is added with threads that automatically update a variable declared dependent on the value of other variables and events. - SIMD.
Instructions running in parallel. - Asink was. (1.9).
Allows the function to sequentially process a sequence of commands, the result of which is waiting for processing. Wait for the result before continuing. - Future: .then is a kind of callback. This defines the function called when processing .
- Enumeration. (1.9).
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).
Darth
void main() {
print("Salut le Monde!");
}
TypeScript
function main() {
console.log("Salut le Monde!");
}
Darth
String str = "Hello en Dart";
TypeScript
var str : string = "Hello en TypeScript";
Darth
var str = "Hello en Dart";
TypeScript
var str = "Hello en TypeScript";
Darth
String x = "$a$b"
TypeScript
var x = a + b;
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");
}
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");
}
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]);
}
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)
...
}
Darth
int x;
while(true) {
x++;
}
do {
x++;
} while(true);
TypeScript
var x: number
while(true) {
x++;
}
do {
x++;
} while(true);
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);
}
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.
Toolbox
- Try the online language. Enter the online code. To test the examples above, you need to place the code in the hand function or add a hand function. All of them were checked.
- Flutter. Dart scripting framework for creating fast Android or iOS apps.
Documents and Resources
- Darts. Description and specifications of the language and boot for Windows. A dedicated editor is also available.
- ECMA 408. Standard specifications.
See also...
- JavaScript и Harmony. How language develops. Version 6 of ECMAScript carries the bulk of Dart's functionality.
- How not to create a new programming language. Is the eternal C syntax the best ?