SlideShare a Scribd company logo
1 of 13
Download to read offline
Introducing



                           http://dartlang.org

Sylvain Jermini, Andrea Chiodoni
JUG Lugano, 9 May 2012




Agenda
   Introduction
   The Dart language
   How to run Dart
   The Dart libraries
   Conclusion
   Discussion




Introduction: Facts
There is an increasing interest for complex modern Web applications:

    Increasing customer requirements
    HTML5 pushing the boundaries
    Device diversification (mobile devices)

And the plug-in era is over!




Introduction: State of the Web
    Good parts

        Easy to write small-medium apps
        Platform independent
        No app installation
        Support incremental development
        Platform improving fast
        Everywhere




Introduction: State of the Web
(cont.)
    Bad parts, Development of large apps is challenging:

        Lack of structure
        No static types
        No support for libs (modularity)
        Poor IDE support
        Slow startup (see http://stevesouders.com/)




Introduction: JavaScript momentum
    JavaScript is "better" than ever:

        Frameworks (jQuery, MVC, ...)
        Community adopting "best parts"
        Some good tools (JSLint)
        Performance
        API (HTML5 and Web API)
        Virtual machine (Google V8)
Introduction: Can JavaScript play the
role?
 ... but can JavaScript play this role?

     http://wtfjs.com/
     https://www.destroyallsoftware.com/talks/wat
     Allen Wirfs-Brock (Mozilla), http://www.infoq.com/presentations/JavaScript-
     Today-and-Tomorrow




Introduction: Google Dart
 Improve the state of the art of Web programming!

 Brand new: October 2011!
 License: Open Source, BSD
 Developed "on the open": http://www.dartlang.org/docs/spec/
 An entire platform: language, libraries and tools
 Run on the client and the server
 Lear from the part: GWT, V8, speed
 Make it available to the entire modern Web




The Dart language
 In one phrase: optionally typed dynamic single inheritance class based purely object
 oriented programming language.
 Concurrent programming through "isolates"
 Familiar to the mainstream programmers
 Efficiently compile to JS
 With some twists and a sizable amount of syntactic sugar (I'm looking at you,
 anonymous inner classes in java).
 An unsound type system: as described by Gilad Bracha: a static analysis tool based on
 heuristics, coupled to a type assertion system




The Dart language: optional typing
 Optionally typed as in:

     the types are annotations
they don't change the runtime semantics
         not for decoration: help catching error (by the compiler and the runtime in checked
         mode), documentation purpose.




The Dart language: familiarity
    classes, interfaces (with some twist) and in a future release, abtract classes ✔
     static keyword variable/methods ✔

     final keyword for constants ✔

    exceptions: try catch finally ✔ with a sane default (unchecked) and a twist: you
    can throw any object.
    same keyword for control flow as you know (skipping the details).
    generics (a simpler but unsound version, maybe more pragmatic? :) )




The Dart language: unfamiliarity for a
java programmer
    operator overriding
    first class function
    optional parameters: default value, named
    closures
    no void, all functions return something. return null is added implicitly if there is no
    return statement.




The Dart language: Functions
String say(String from, String msg) {
  return "$from says $msg";//string interpolation
}

Short one line version:

String say(String from, String msg) => "$from says $msg"; //implicit return

Without type annotation:

say(from, msg) => "$from says $msg";




The Dart language: Functions:
optional parameters
Optional:

 say(from, msg, [device]) {
   //default value will be null
 }

Optional with default value:

 say(from, msg, [device = "blah"]) {
   //default value will be "blah"
 }

Use of named parameter:

 say("Bob", "Howdy", device: "tin can and string")




The Dart language: First class
functions
Classic:

 List ages = [1,4,5,7,10,14,21];
 List oddAges = ages.filter((i) => i % 2 == 1);

Assign to a variable:

 var loudify = (msg) => '!!! ${msg.toUpperCase()} !!!';
 print(loudify('hello'));




The Dart language: Function, closures
As you would expect:

 Function makeAdder(num n) {
   return (num i) => n + i;
 }


 main() {
   var add2 = makeAdder(2);
   print(add2(3)); // 5
 }




The Dart language: Strings with sugar
By the way, like js, ' and " are both valid identifier:

Interpolation:

 var s = 'string interpolation';


 print('Dart has $s, which is very handy.');
 print('That deserves all caps. ${s.toUpperCase()}'
       ' is very handy!'); //adjacent string literals
                           //are concatenated

Multiline:

 var s1 = '''
   You can create
   multi-line strings like this one.
 ''';




The Dart language: Collections
Literals for collections (and they are fully mutable, unlike some proposal that floated for
java7):

List:

 var list = [1,2,3];

Maps:

 var gifts = {// a map literal
 // keys       values
   "first" : "partridge",
   "second" : "turtledoves",
   "fifth" : "golden rings"};




The Dart language: Classes
Familiar single inheritance class system:

 class Point {
        num x, y;
        // syntactic sugar for this.x = x and this.y = y
        Point(this.x, this.y);
 }

Named constructors:
class Point {
     num x, y;

     // named constructor
     Point.fromJson(Map json) : x = json['x'], y = json['y'];
     Point(this.x, this.y);
 }


 var jsonData = JSON.parse('{"x":1, "y":2}');
 var point = new Point.fromJson(jsonData);




The Dart language: Classes (cnt)
No surprises at all:

 class Television {
   turnOn() {
     _illuminateDisplay();
     _activeIrSensor();
   }
 }

You declare a member private with an underscore.

 class SmartTelevision extends Television {
   turnOn() {
     super.turnOn();
     _bootNetworkInterface();
     _initializeMemory();
     _upgradeApps();
   }
 }




The Dart language: Classes (some
differences)
Initializer list for final variables (as they must be assigned before:
class Button {
   final Collection handlers;
   final String domId;
   final Element elem;


               // what follows the : is the initializer list
     Button(domId) : domId = domId,
                     handlers = [],
                     elem = document.query(domId) {


         bindHandlers();
     }

     bindHandlers() {
       // ...
     }
 }




The Dart language: Classes (some
sugar)
Getter/Setter:

 class Rectangle {
   num left, top, width, height;


     Rectangle(this.left, this.top, this.width, this.height);


     num get   right()             =>   left + width;
         set   right(num value)    =>   left = value - width;
     num get   bottom()            =>   top + height;
         set   bottom(num value)   =>   top = value - height;
 }

Appear as a property:

 var rect = new Rectangle(3, 4, 20, 15);
 print(rect.left); // 3
 rect.right = 12;
 print(rect.left); // -8




The Dart language: Interfaces
Like java:
interface Hashable {
   int hashCode();
 }

Not exactly like java:

 interface HashablePoint extends Hashable {
   num x, y;
 }



 class Point implements HashablePoint {
   num x, y; // required by HashablePoint


     // required by Hashable
     int hashCode() {
       ...
     }
 }




The Dart language: Interfaces (cnt)
Not java at all: constructors in interface with a default specified concrete class:

 interface ObjectCache default MemoryCache {
   ObjectCache();
   ...
 }


 class MemoryCache implements ObjectCache {
   ...
 }

Then you can do:

 var cache = new ObjectCache();// same as: new MemoryCache()




The Dart language: Isolates
      Concurrency done right: shared nothing approach. (no need for a concurrent GC)
      Comunication through message passing. Messages are deep copied.

Limitation for the message content:

      A primitive value (null, num, bool, double, String)
      An instance of SendPort
      A list or map whose elements are any of the above, including other lists and maps
In special circumstances (like spawning a function), an object of any type




The Dart language: Isolates cnt.
Send (not blocking) and receive.

 #import('dart:isolate');


 echo() {
   port.receive((msg, SendPort reply) {
     print("I received: $msg");
   });
 }

When any isolate starts (even the main script of the application), a default ReceivePort is
created for it. This port is available from the top-level getter port defined in this library.

 main() {
   SendPort sendPort = spawnFunction(echo);
   sendPort.send("Hello from main");
 }




The Dart language: Isolates cnt.
call() (which return a Future object) and receive() :

 #import('dart:isolate');


 echo() {
   port.receive((msg, SendPort reply) {
     reply.send("I received: $msg");
     });
 }


 main() {
   SendPort sendPort = spawnFunction(echo);
   sendPort.call("Hello from main").then((reply) {
     print(reply);    // I received: Hello from main
     });
 }




How to run Dart
      on the Browser

           Dart-to-JavaScript compiler: http://www.dartlang.org/docs/getting-
           started/editor/
Chromium with the Dart VM: http://www.dartlang.org/dartium/

    on the Server

         Dart VM: http://www.dartlang.org/docs/getting-started/sdk/
               High performance
               V8 style
               embeddable




The Dart libraries
    Libraries help you create a modular and shareable code base. Libraries not only
    provide APIs, but are a unit of privacy: they can hide implementation details such as
    private variables. Source: http://www.dartlang.org/language-tour/#libraries

The goal is to provide a rich set of libs:

    http://api.dartlang.org/
    http://dartwatch.com/index.php/dart-packages/

Libraries and a module system ( http://goo.gl/jml49) are a work in progress!
                              (http://goo.gl/jml49 )




The Dart libraries: dart:core
    Defines:

         Interfaces for the core types: num, Collection, Function, String,..
         Exceptions

    Imported by default

    Both client and server

    see http://api.dartlang.org/dart_core.html




The Dart libraries: dart:io
    Mainly (HttpClient available) for the server side
    HttpServer, HttpClient, File, Timer, Sockets, WebSockets, InputStream, OutputStream
    Dart is a single-threaded programming language -> non blocking I/O operations
    (inspired by Node.js)

         Dart VM runs in an event loop with an associated event queue of pending
         asynchronous operations
         The VM terminates when it has executed the current code to completion and no
more pending operations are in the queue

    see http://api.dartlang.org/io.html




The Dart libraries: dart:html
    A clean DOM API

           Simpler names HTMLElement -> Element
                   names:
           Better querying elem.getElementById('foo'); -> elem.query('#foo');
                  querying:
           Use real collections elem.getAttribute('name'); -> elem.attributes['name'];
                    collections:
           Use constructors document.createElement('div'); -> new Element.tag('div');
               constructors:
           Events elem.addEventListener('click', (event) => print('click!'), false); ->
           Events:
           elem.on.click.add((event) => print('click!'));

    see http://api.dartlang.org/html.html




Conclusion
    Promising
    State: currently only a technology preview!
    The question: Will Dart be adopted?




Discussion
    Matter of choice:

           What about JavaScript as a "First language"?
           And JavaScript as the assembler of the Web ("to JavaScript" transpilers )?
           Things like GWT, Dart, CoffeeScript, Closure compiler...

    Same language on both client and server (GWT, Node.js, Dart)

    What's happen to GWT?




Thanks for you attention
Samples:

    https://github.com/syjer/weakdot
    https://github.com/chiodonia/dartlang
Resources
   http://dartlang.org
   Specifications: http://www.dartlang.org/docs/spec/
   Is Dart solving the famous Java puzzlers? See
   http://www.dartlang.org/articles/puzzlers/chapter-1.html
   Style guides: http://www.dartlang.org/articles/style-guide/
   FAQ: http://www.dartlang.org/support/faq.html

00000020;com.apple.app-sandbox.read-
write;00000001;0e000002;00000000006ba9d7;/users/chiodonia/dropbox/notes/dart/dart.md

More Related Content

What's hot

Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web appschrisbuckett
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovypaulbowler
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type scriptDmitrii Stoian
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersKostas Saidis
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_scriptVijay Kalyan
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationAndrea Paciolla
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbowschrisbuckett
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentJoost de Vries
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptLaurence Svekis ✔
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Guillaume Laforge
 

What's hot (20)

Dart structured web apps
Dart   structured web appsDart   structured web apps
Dart structured web apps
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript application
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Dart
DartDart
Dart
 
Dart, unicorns and rainbows
Dart, unicorns and rainbowsDart, unicorns and rainbows
Dart, unicorns and rainbows
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
Web programming
Web programmingWeb programming
Web programming
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser development
 
Generics
GenericsGenerics
Generics
 
Java script
Java scriptJava script
Java script
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 

Similar to Dart

Bringing your app to the web with Dart - Chris Buckett (Entity Group)
Bringing your app to the web with Dart - Chris Buckett (Entity Group)Bringing your app to the web with Dart - Chris Buckett (Entity Group)
Bringing your app to the web with Dart - Chris Buckett (Entity Group)jaxLondonConference
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaPeter Maas
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005Tugdual Grall
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoRodolfo Carvalho
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersAlessandro Sanino
 
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Data Con LA
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013Robert Metzger
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
Dart London hackathon
Dart  London hackathonDart  London hackathon
Dart London hackathonchrisbuckett
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepChandramouli Biyyala
 

Similar to Dart (20)

Bringing your app to the web with Dart - Chris Buckett (Entity Group)
Bringing your app to the web with Dart - Chris Buckett (Entity Group)Bringing your app to the web with Dart - Chris Buckett (Entity Group)
Bringing your app to the web with Dart - Chris Buckett (Entity Group)
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
Dart ppt
Dart pptDart ppt
Dart ppt
 
Dart programming language
Dart programming languageDart programming language
Dart programming language
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
 
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
basic_java.ppt
basic_java.pptbasic_java.ppt
basic_java.ppt
 
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
Stratosphere System Overview Big Data Beers Berlin. 20.11.2013
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Dart London hackathon
Dart  London hackathonDart  London hackathon
Dart London hackathon
 
Dart on server - Meetup 18/05/2017
Dart on server - Meetup 18/05/2017Dart on server - Meetup 18/05/2017
Dart on server - Meetup 18/05/2017
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Flutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by StepFlutter tutorial for Beginner Step by Step
Flutter tutorial for Beginner Step by Step
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Dart

  • 1. Introducing http://dartlang.org Sylvain Jermini, Andrea Chiodoni JUG Lugano, 9 May 2012 Agenda Introduction The Dart language How to run Dart The Dart libraries Conclusion Discussion Introduction: Facts
  • 2. There is an increasing interest for complex modern Web applications: Increasing customer requirements HTML5 pushing the boundaries Device diversification (mobile devices) And the plug-in era is over! Introduction: State of the Web Good parts Easy to write small-medium apps Platform independent No app installation Support incremental development Platform improving fast Everywhere Introduction: State of the Web (cont.) Bad parts, Development of large apps is challenging: Lack of structure No static types No support for libs (modularity) Poor IDE support Slow startup (see http://stevesouders.com/) Introduction: JavaScript momentum JavaScript is "better" than ever: Frameworks (jQuery, MVC, ...) Community adopting "best parts" Some good tools (JSLint) Performance API (HTML5 and Web API) Virtual machine (Google V8)
  • 3. Introduction: Can JavaScript play the role? ... but can JavaScript play this role? http://wtfjs.com/ https://www.destroyallsoftware.com/talks/wat Allen Wirfs-Brock (Mozilla), http://www.infoq.com/presentations/JavaScript- Today-and-Tomorrow Introduction: Google Dart Improve the state of the art of Web programming! Brand new: October 2011! License: Open Source, BSD Developed "on the open": http://www.dartlang.org/docs/spec/ An entire platform: language, libraries and tools Run on the client and the server Lear from the part: GWT, V8, speed Make it available to the entire modern Web The Dart language In one phrase: optionally typed dynamic single inheritance class based purely object oriented programming language. Concurrent programming through "isolates" Familiar to the mainstream programmers Efficiently compile to JS With some twists and a sizable amount of syntactic sugar (I'm looking at you, anonymous inner classes in java). An unsound type system: as described by Gilad Bracha: a static analysis tool based on heuristics, coupled to a type assertion system The Dart language: optional typing Optionally typed as in: the types are annotations
  • 4. they don't change the runtime semantics not for decoration: help catching error (by the compiler and the runtime in checked mode), documentation purpose. The Dart language: familiarity classes, interfaces (with some twist) and in a future release, abtract classes ✔ static keyword variable/methods ✔ final keyword for constants ✔ exceptions: try catch finally ✔ with a sane default (unchecked) and a twist: you can throw any object. same keyword for control flow as you know (skipping the details). generics (a simpler but unsound version, maybe more pragmatic? :) ) The Dart language: unfamiliarity for a java programmer operator overriding first class function optional parameters: default value, named closures no void, all functions return something. return null is added implicitly if there is no return statement. The Dart language: Functions String say(String from, String msg) { return "$from says $msg";//string interpolation } Short one line version: String say(String from, String msg) => "$from says $msg"; //implicit return Without type annotation: say(from, msg) => "$from says $msg"; The Dart language: Functions:
  • 5. optional parameters Optional: say(from, msg, [device]) { //default value will be null } Optional with default value: say(from, msg, [device = "blah"]) { //default value will be "blah" } Use of named parameter: say("Bob", "Howdy", device: "tin can and string") The Dart language: First class functions Classic: List ages = [1,4,5,7,10,14,21]; List oddAges = ages.filter((i) => i % 2 == 1); Assign to a variable: var loudify = (msg) => '!!! ${msg.toUpperCase()} !!!'; print(loudify('hello')); The Dart language: Function, closures As you would expect: Function makeAdder(num n) { return (num i) => n + i; } main() { var add2 = makeAdder(2); print(add2(3)); // 5 } The Dart language: Strings with sugar
  • 6. By the way, like js, ' and " are both valid identifier: Interpolation: var s = 'string interpolation'; print('Dart has $s, which is very handy.'); print('That deserves all caps. ${s.toUpperCase()}' ' is very handy!'); //adjacent string literals //are concatenated Multiline: var s1 = ''' You can create multi-line strings like this one. '''; The Dart language: Collections Literals for collections (and they are fully mutable, unlike some proposal that floated for java7): List: var list = [1,2,3]; Maps: var gifts = {// a map literal // keys values "first" : "partridge", "second" : "turtledoves", "fifth" : "golden rings"}; The Dart language: Classes Familiar single inheritance class system: class Point { num x, y; // syntactic sugar for this.x = x and this.y = y Point(this.x, this.y); } Named constructors:
  • 7. class Point { num x, y; // named constructor Point.fromJson(Map json) : x = json['x'], y = json['y']; Point(this.x, this.y); } var jsonData = JSON.parse('{"x":1, "y":2}'); var point = new Point.fromJson(jsonData); The Dart language: Classes (cnt) No surprises at all: class Television { turnOn() { _illuminateDisplay(); _activeIrSensor(); } } You declare a member private with an underscore. class SmartTelevision extends Television { turnOn() { super.turnOn(); _bootNetworkInterface(); _initializeMemory(); _upgradeApps(); } } The Dart language: Classes (some differences) Initializer list for final variables (as they must be assigned before:
  • 8. class Button { final Collection handlers; final String domId; final Element elem; // what follows the : is the initializer list Button(domId) : domId = domId, handlers = [], elem = document.query(domId) { bindHandlers(); } bindHandlers() { // ... } } The Dart language: Classes (some sugar) Getter/Setter: class Rectangle { num left, top, width, height; Rectangle(this.left, this.top, this.width, this.height); num get right() => left + width; set right(num value) => left = value - width; num get bottom() => top + height; set bottom(num value) => top = value - height; } Appear as a property: var rect = new Rectangle(3, 4, 20, 15); print(rect.left); // 3 rect.right = 12; print(rect.left); // -8 The Dart language: Interfaces Like java:
  • 9. interface Hashable { int hashCode(); } Not exactly like java: interface HashablePoint extends Hashable { num x, y; } class Point implements HashablePoint { num x, y; // required by HashablePoint // required by Hashable int hashCode() { ... } } The Dart language: Interfaces (cnt) Not java at all: constructors in interface with a default specified concrete class: interface ObjectCache default MemoryCache { ObjectCache(); ... } class MemoryCache implements ObjectCache { ... } Then you can do: var cache = new ObjectCache();// same as: new MemoryCache() The Dart language: Isolates Concurrency done right: shared nothing approach. (no need for a concurrent GC) Comunication through message passing. Messages are deep copied. Limitation for the message content: A primitive value (null, num, bool, double, String) An instance of SendPort A list or map whose elements are any of the above, including other lists and maps
  • 10. In special circumstances (like spawning a function), an object of any type The Dart language: Isolates cnt. Send (not blocking) and receive. #import('dart:isolate'); echo() { port.receive((msg, SendPort reply) { print("I received: $msg"); }); } When any isolate starts (even the main script of the application), a default ReceivePort is created for it. This port is available from the top-level getter port defined in this library. main() { SendPort sendPort = spawnFunction(echo); sendPort.send("Hello from main"); } The Dart language: Isolates cnt. call() (which return a Future object) and receive() : #import('dart:isolate'); echo() { port.receive((msg, SendPort reply) { reply.send("I received: $msg"); }); } main() { SendPort sendPort = spawnFunction(echo); sendPort.call("Hello from main").then((reply) { print(reply); // I received: Hello from main }); } How to run Dart on the Browser Dart-to-JavaScript compiler: http://www.dartlang.org/docs/getting- started/editor/
  • 11. Chromium with the Dart VM: http://www.dartlang.org/dartium/ on the Server Dart VM: http://www.dartlang.org/docs/getting-started/sdk/ High performance V8 style embeddable The Dart libraries Libraries help you create a modular and shareable code base. Libraries not only provide APIs, but are a unit of privacy: they can hide implementation details such as private variables. Source: http://www.dartlang.org/language-tour/#libraries The goal is to provide a rich set of libs: http://api.dartlang.org/ http://dartwatch.com/index.php/dart-packages/ Libraries and a module system ( http://goo.gl/jml49) are a work in progress! (http://goo.gl/jml49 ) The Dart libraries: dart:core Defines: Interfaces for the core types: num, Collection, Function, String,.. Exceptions Imported by default Both client and server see http://api.dartlang.org/dart_core.html The Dart libraries: dart:io Mainly (HttpClient available) for the server side HttpServer, HttpClient, File, Timer, Sockets, WebSockets, InputStream, OutputStream Dart is a single-threaded programming language -> non blocking I/O operations (inspired by Node.js) Dart VM runs in an event loop with an associated event queue of pending asynchronous operations The VM terminates when it has executed the current code to completion and no
  • 12. more pending operations are in the queue see http://api.dartlang.org/io.html The Dart libraries: dart:html A clean DOM API Simpler names HTMLElement -> Element names: Better querying elem.getElementById('foo'); -> elem.query('#foo'); querying: Use real collections elem.getAttribute('name'); -> elem.attributes['name']; collections: Use constructors document.createElement('div'); -> new Element.tag('div'); constructors: Events elem.addEventListener('click', (event) => print('click!'), false); -> Events: elem.on.click.add((event) => print('click!')); see http://api.dartlang.org/html.html Conclusion Promising State: currently only a technology preview! The question: Will Dart be adopted? Discussion Matter of choice: What about JavaScript as a "First language"? And JavaScript as the assembler of the Web ("to JavaScript" transpilers )? Things like GWT, Dart, CoffeeScript, Closure compiler... Same language on both client and server (GWT, Node.js, Dart) What's happen to GWT? Thanks for you attention Samples: https://github.com/syjer/weakdot https://github.com/chiodonia/dartlang
  • 13. Resources http://dartlang.org Specifications: http://www.dartlang.org/docs/spec/ Is Dart solving the famous Java puzzlers? See http://www.dartlang.org/articles/puzzlers/chapter-1.html Style guides: http://www.dartlang.org/articles/style-guide/ FAQ: http://www.dartlang.org/support/faq.html 00000020;com.apple.app-sandbox.read- write;00000001;0e000002;00000000006ba9d7;/users/chiodonia/dropbox/notes/dart/dart.md