EDITING BOARD
RO
EN
×
▼ BROWSE ISSUES ▼
Issue 35

Keep Calm and Start playing Dart

Kuki Edina
Tester Senior Analyst



PROGRAMMING

S is not missing! Nevertheless s, I'm not here to give out ideas to managers on how to reduce recreational office time by cutting down the number of missiles; neither am I here to introduce a single-chance Russian-style version of the well-known game. This is something from our other big brother, namely Don't-be-evil Google. Thanks to his prominent expertise around web technologies, in October 2011, Aarhus, the city of Bjarne Stroustrup and Lars Bak could witness the birth of another potential revolutionary of the IT industry, as being the place where Dart was first officially unveiled.

And like any responsible brother would do when presenting, even better, inviting us to try out his new gadget, we could hear the initial set of hows, whys and wherefores and since then, let's not say he would be showing off, yet keeps us up to date about its very latest upgrades.

Still here? Still calm? Then, let's come to the Dart's side!

This time no cookies, but energizing syntactic sugar - we do need some sweets, right - and a huge set of new approaches are offered to improve web-programmer's experience.

As a beginning, Dart does not simply refer to a programming language. Better, imagine an entire solution and toolchain that aims to enable the development and deployment of high-performance, structured, scalable web applications, and if someone has experience with such apps, we must admit that our big brother has - just for the record, you might remember Google's Chrome or V8 JavaScript engine, which did have something to do with the immense speed-up of our browsers.

The bright plan behind Dart would be to outbalance the far cry from how the browsers have been improved yet the startup, evolvement and maintenance of complex web apps were not.

Dart is fresh, quick to catch up with, coming with an all-inclusive toolchain, fully featured tutorials, and extended API with complete documentation and also strong support for the growing community around it - many of the programmers hoping that JavaScript could be stopped in its lonely reign of the web.

And this would also fit in the dark plan. All the above facts, separately or combined at the end would imply more and faster websites, and such even more surface for advertisements and faster DoubleClick - isn't it?

So, what's included in all-inclusive?

We do get the Dart language, that is:

We can opt for its own Dart Editor or decide to integrate a plugin in one of the IDEs we are already familiar with, like WebStorm, IntelliJ or Eclipse.

Either way, we still get handy command-line tools from the SDK, like:

We are free to use the Dart Virtual Machine standalone to run command-line apps, server-side scripts, servers or other Dart apps not intended to be launched from browsers. The Dart VM has been as well extended with SIMD (Single-Instruction Multiple-Data) operations. Considering that in the latest processors around 30% of the die's size is dedicated for SIMD processes, like NEON and vector operations, Dart VM opens and benefits from a lot more space on the CPU.

During development we are recommended to use the special version of Chromium, Dartium, with integrated Dart VM, as its performance and handy features - like simply reloading the web page instead recompile - can save us a lot of time.

The list does not end here and the only small-lettered section we should be indeed aware of is referring to the continuous improvements on the language, tools, stability and benchmarking-results.

Would this sound utopic for you? Don't be evil, read further.

So much talk, give us some code!

At minimum, a Dart application has:

There are two kinds of Dart applications: command-line applications and web applications. A command-line application is a standalone program that we run in the Dart VM from the command-line in a terminal window. A web application is hosted on a web page and runs in a browser (either directly in Dartium or by compiling it first to JavaScript). See below the basic architectural layouts.

Fig.1 Command line app run in Dart VM

Fig.2 Run a Dart web app from Dartium

Fig. 3 Run Dart in any modern browser compiled to JS

Finally, let's have a deeper insight on a basic Dart program:

import ‘dart:async’;
import ‘dart:io’;

class Counter {            // In Dart every class defaults to Object.

  var _toCount;            // If begins with ‘_’ defaults to private.
  num counted;

  // Getters and setters (if appropriate) are coming by default.

  // Syntactic sugar for setting _toCount
  // before the constructor body runs.
  Counter (this._toCount);    

  // An example of a Named Constructor.
  Counter.stave (String text, String s) {    
    for (var char in text.split(‘’)) {
      if (char.toLowerCase() == s.toLowerCase())
        counted++;    
    }
  }

  // Define another function.
  void printCounted() => print(“$_toCount occurred $counted times.”);

};                    

// Top-level function; the application execution starts here
main() {

  // Declare and initialize some variables.
  var stave = “S”;        
  File file = new File (“Keep_Calm.txt”);

  // Lengthy computations handled asynchronously with Future.
  Future future = file.readAsString();
  future.then((String content) {
    var sCounter = new Counter.stave(content, ‘S’);
    sCounter.printCounted();
    })
    .catchError((e) {
    print (‘Counter encountered $e error!’)
    });
}

As promised, Dart does come with familiar syntax but already these few lines reflect some ideas on how the propagated Dart-future would look like in practice.

We've met two core libraries, io and async; the named constructor, the fat-arrow syntax for thinner one-line functions, string interpolation usage and some more interesting part happening around then. Remember Dart's asynchronous event handling mentioned earlier? It looks like this. Fire an event, be right there when it gets finished and get your job done with it within a close lexical scope.

Besides the io and async libraries used earlier, other base SDK libraries are: core, html, math, mirrors, isolate, _indexeddb, collection, _webgl or _websql.

We also get unit-testing and mock packages, a Headless-Chrome for command-line testing and lately, native Dart support within drone.io for continuous integration.

In less than three years, Ecma International has standardized the first edition of Dart, and despite the slow start of its adoption, last autumn Dart already took a place on the Tiobe Index language popularity top 20 list ahead of Microsoft's F# and Apple's Swift, with the comment "But now that the Dart-to-JavaScript compiler is mature and claims to generate even faster code than handwritten JavaScript, the Dart language seems to have a bright future."

Seeking for even more?

In a few days, the first Dart Summit will take place in San Francisco, where we can hear further calming news about the long-term strategy and commitment to Dart and further exciting innovative ideas and use cases about Dart in production.

Till then, stop reading and start playing! There are plenty online resources and an actively contributing community on google+, github and stackoverflow to help us aiming and scoring with one single Dart.

Check out: dartlang.org, dartosphere.org, g.co/dartisans

Conference TSM

VIDEO: ISSUE 109 LAUNCH EVENT

Sponsors

  • Accenture
  • BT Code Crafters
  • Accesa
  • Bosch
  • Betfair
  • MHP
  • BoatyardX
  • .msg systems
  • P3 group
  • Ing Hubs
  • Cognizant Softvision
  • Colors in projects

VIDEO: ISSUE 109 LAUNCH EVENT