Bullseye!

Let's play Dart

Florian Hirschadorsys

@lefloh / github.com/lefloh

Dart is a new language with tools and libraries for scalable web app engineering

Why?

  • Productivity
  • Scalability
  • Speed / Startup Time (mobile)
  • Need for Types
  • Need for modules, packages or libraries

Design Goals

  • Structured yet flexible programming language for the web.
  • Familiar and natural to programmers.
  • Appropriate for the full range of devices on the web.
  • Tools to support all major modern browsers.

Dart: An Introduction
Florian Loitsch / Riviera DEV, 20.10.2011

Critics

“I guarantee you that Apple and Microsoft (...) will never embed the Dart VM. So 'Works best in Chrome' and even 'Works only in Chrome' are new norms promulgated intentionally by Google.”

— Brendan Eich

Speed of Dart

  • 10.10.2010: First Announcement on GOTO Aarhus
  • 14.11.2013: 1.0
  • 25.06.2014: 1.3 – ECMA-408
  • 26.06.2014: 1.5
  • 27.08.2014: 1.6
  • 15.10.2014: 1.7
  • 28.11.2014: 1.8

Hello World


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

script-like


const THE_ANSWER = 42;
print('half of the answer is ${THE_ANSWER / 2}');

var list = [1, 2, 3];
list.forEach((e) => print(e));

var map = {
  'foo' : 12
};

map['bar'] = 13;
map.forEach((k, v) => print('$k * 2 = ${v * 2}'));

concat(a, b) => a + b;
var foobar = concat('foo', 'bar');
				

Java-like


/// the superhero class
class Superhero {
  
  String name;
  
  Superhero(this.name);
  
  toString() => 'I am $name!';
  
}

main() {
  Superhero batman = new Superhero('Batman');
  print(batman);    
}

				

Optionally typed

  • Dynamic typed language
  • Types are optional and don't change the behaviour
  • Types for: Documentation, error detection, performance
  • Checked mode (default for development)

Optional Types in Dart / Why Dart Types Are Optional and Unsound


// convention
void publicMethod(String something) {
  var now = new DateTime.now();
}				
				

No surprises!

Familiar

  • uses curly braces :)
  • only true is truthy
  • only null – no undefined
  • no hoisting

Syntactic Sugar


class Superhero extends Person with SuperPower {
  String name;
  String _realName;
    
  Superhero.withRealName(this._realName);
  
  String get realName => _realName;
  set realName(realName) => _realName = realName is String ? realName : 'UNKNOWN'; 
  
  void train({times: 1}) { }
  Team operator +(Superhero other) => new Team([this, other]);
}

main() {
  var superman = new Superhero.withRealName("Clark Kent")..name = "Superman";
  superman.train(times: 4);
}				
				

new


class Cache {
  
  static final Cache _INSTANCE = new Cache._internal();
  
  static Map<String, String> _store;
  
  factory Cache() {
    if (_store == null) {
      _store = <String, String>{};
    }
    return _INSTANCE;
  }
  
  Cache._internal();

}
var cache = new Cache();
				

Libraries

  • built-in modules
  • unit of privacy
  • every Dart App is a library
  • Pub the package manager (> 1400 libraries)
        
library testlib;

import 'dart:math' as m show PI;
import 'package:bootjack/bootjack.dart' hide Alert;

part '04_testlib_part.dart'; 

Build and Deployment

  • dart2js
  • Dart VM (Standalone / Chromium)
  • Language VM (no bytecode!)
  • Full / Script / Object Snapshots
  • Docker Images on AppEngine

Performance

Dart Performance

Would you play dart?

“There are two candidates for the TIOBE programming language of the year award that will be announced around the 1st of January 2015. These are statistical language R (+1.38%) and Apple's new Swift language (+1.06%). Apart from these, also JavaScript and Dart have a chance to win.”

TIOBE Index December 2014