Building Single-Page Web Appplications in dart - Devoxx France 2013

52
18h20 - 18h50 - Miles Davis B Building a Single-Page Web Application in Dart

description

 

Transcript of Building Single-Page Web Appplications in dart - Devoxx France 2013

Page 1: Building Single-Page Web Appplications in dart - Devoxx France 2013

18h20 - 18h50 - Miles Davis B

Building a Single-Page Web Application in Dart

Page 2: Building Single-Page Web Appplications in dart - Devoxx France 2013

27 au 29 mars 2013

Building a Single-Page Web Application in Dart

Yohan BeschiSo@t – Java Developer

@yohanbeschi

Page 3: Building Single-Page Web Appplications in dart - Devoxx France 2013

Yohan Beschi

•Started programming at 15 – 100% self-taught

•Languages (Assembly, C/C++, Java, Python)

•Blogger, Speaker, Instructor

•Started Dart 6 months ago

Page 4: Building Single-Page Web Appplications in dart - Devoxx France 2013

Building Uis - Javascript ?

Page 5: Building Single-Page Web Appplications in dart - Devoxx France 2013

Building Uis - Java ?

Page 6: Building Single-Page Web Appplications in dart - Devoxx France 2013

Building Uis - But how ?

Page 7: Building Single-Page Web Appplications in dart - Devoxx France 2013

Programmatic Components with GWT

Page 8: Building Single-Page Web Appplications in dart - Devoxx France 2013

Java + GWT = Too verbose!

More than 100

lines

Page 9: Building Single-Page Web Appplications in dart - Devoxx France 2013

The Dart Way

Table<User> table = new Table (sorting:true) ..addColumn('ID', new TextCell((User o) => o.id)) ..addColumn('First name', new TextCell((User o) => o.firstName)) ..addColumn('Last name', new TextCell((User o) => o.lastName)) ..addColumn('Age', new TextCell((User o) => o.age)) ..setData(objs);

Page 10: Building Single-Page Web Appplications in dart - Devoxx France 2013

The Dart Way

Table<User> table = new Table (sorting:true) ..addColumn('ID', new TextCell((User o) => o.id)) ..addColumn('First name', new TextCell((User o) => o.firstName)) ..addColumn('Last name', new TextCell((User o) => o.lastName)) ..addColumn('Age', new TextCell((User o) => o.age)) ..setData(objs);

6lignes

Page 11: Building Single-Page Web Appplications in dart - Devoxx France 2013

Dart is the winner

Page 12: Building Single-Page Web Appplications in dart - Devoxx France 2013

Once upon a time…

Page 13: Building Single-Page Web Appplications in dart - Devoxx France 2013

Programmer productivity

Page 14: Building Single-Page Web Appplications in dart - Devoxx France 2013

Application scalability

Page 15: Building Single-Page Web Appplications in dart - Devoxx France 2013

Raw execution speed

Page 16: Building Single-Page Web Appplications in dart - Devoxx France 2013

Startup performance

Page 17: Building Single-Page Web Appplications in dart - Devoxx France 2013

And here we are!

•Open Source (BSD)

•Structured

•Anti-revolutionary

•Same goals as new Javascript frameworks

•The goal is to not break the web

Page 18: Building Single-Page Web Appplications in dart - Devoxx France 2013

Dart - The language

Page 19: Building Single-Page Web Appplications in dart - Devoxx France 2013

Abstract Class

abstract class abstract class Validatable {Validatable {

}}

Page 20: Building Single-Page Web Appplications in dart - Devoxx France 2013

Abstract Method

abstract class abstract class Validatable {Validatable {

List<Object> valuesToValidate();List<Object> valuesToValidate();

}}

Page 21: Building Single-Page Web Appplications in dart - Devoxx France 2013

Generics

abstract class abstract class Validator<TValidator<T extendsextends Validatable> {Validatable> {

}}

Page 22: Building Single-Page Web Appplications in dart - Devoxx France 2013

Implementing a method – 1/4

abstract class abstract class Validator<TValidator<T extendsextends Validatable> {Validatable> {

boolbool validate(T object) { validate(T object) {

}}

}}

Page 23: Building Single-Page Web Appplications in dart - Devoxx France 2013

Implementing a method - for in – 2/4

abstract class abstract class Validator<TValidator<T extendsextends Validatable> {Validatable> {

boolbool validate(T object) { validate(T object) {

forfor (Object obj (Object obj inin object.valuesToValidate()) {object.valuesToValidate()) {

}}

}}

}}

Page 24: Building Single-Page Web Appplications in dart - Devoxx France 2013

Implementing a method – 3/4

abstract class abstract class Validator<TValidator<T extendsextends Validatable> {Validatable> {

boolbool validate(T object) { validate(T object) {

forfor (Object obj (Object obj inin object.valuesToValidate()) {object.valuesToValidate()) {

ifif (StringUtils.isEmpty(obj.toString())) {(StringUtils.isEmpty(obj.toString())) {

}}

}}

}}

}}

Page 25: Building Single-Page Web Appplications in dart - Devoxx France 2013

Implementing a method – 4/4

abstract class abstract class Validator<TValidator<T extendsextends Validatable> {Validatable> {

boolbool validate(T object) { validate(T object) {

forfor (Object obj (Object obj inin object.valuesToValidate()) {object.valuesToValidate()) {

ifif (StringUtils.isEmpty(obj.toString())) {(StringUtils.isEmpty(obj.toString())) {

returnreturn falsefalse;;

}}

}}

returnreturn truetrue;;

}}

}}

Page 26: Building Single-Page Web Appplications in dart - Devoxx France 2013

Concrete class

classclass User { User {

}}

Page 27: Building Single-Page Web Appplications in dart - Devoxx France 2013

Class as Interface

classclass User User implements implements Validatable {Validatable {

}}

Page 28: Building Single-Page Web Appplications in dart - Devoxx France 2013

Class members

classclass User User implements implements Validatable {Validatable {

String username;String username;

String password;String password;

}}

Page 29: Building Single-Page Web Appplications in dart - Devoxx France 2013

Private Class members

classclass User User implements implements Validatable {Validatable {

String _username;String _username;

String _password;String _password;

}}

Page 30: Building Single-Page Web Appplications in dart - Devoxx France 2013

Accessors

classclass User User implements implements Validatable {Validatable {

String _username;String _username;

String _password;String _password;

String String getget username => username => thisthis._username;._username;

String String getget password => password => thisthis._password;._password;

setset username(String username) username(String username)

=> => thisthis._username = username;._username = username;

setset password => password => thisthis._password = password;._password = password;

}}

Page 31: Building Single-Page Web Appplications in dart - Devoxx France 2013

Constructor – Sugar Syntax

classclass User User implements implements Validatable {Validatable {

String _username;String _username;

String _password;String _password;

User(String User(String thisthis._username, String ._username, String thisthis._password);._password);

}}

Page 32: Building Single-Page Web Appplications in dart - Devoxx France 2013

Implementing an abstract method

classclass User User implements implements Validatable {Validatable {

String _username;String _username;

String _password;String _password;

User(String User(String thisthis._username, String ._username, String thisthis._password);._password);

List<Object> valuesToValidate() {List<Object> valuesToValidate() {

returnreturn [_username, _password]; [_username, _password];

}}

}}

Page 33: Building Single-Page Web Appplications in dart - Devoxx France 2013

Dart Reference API

•Core

•HTML

•Async

•IO

•Crypto

•JSON

•Mirrors

•UTF

•Unit Testing & Mocks

•Math

•Logging

•URI

• I18N

•etc.

Page 34: Building Single-Page Web Appplications in dart - Devoxx France 2013

But there is more…

•Mixins

•Optionally typed

•Top level functions

•Mono process

Page 35: Building Single-Page Web Appplications in dart - Devoxx France 2013

Isolates

Page 36: Building Single-Page Web Appplications in dart - Devoxx France 2013

Dart Ecosystem

Page 37: Building Single-Page Web Appplications in dart - Devoxx France 2013

Virtual Machines

Page 38: Building Single-Page Web Appplications in dart - Devoxx France 2013

Dartium

Page 39: Building Single-Page Web Appplications in dart - Devoxx France 2013

DartEditor

Page 40: Building Single-Page Web Appplications in dart - Devoxx France 2013

Plugins

Page 41: Building Single-Page Web Appplications in dart - Devoxx France 2013

dart2js

Page 42: Building Single-Page Web Appplications in dart - Devoxx France 2013

dart2js

Page 43: Building Single-Page Web Appplications in dart - Devoxx France 2013

dart2js

•Target HTML5

•Tree Shaking

•Aggregation/Minification

•Optimization

Page 44: Building Single-Page Web Appplications in dart - Devoxx France 2013

Pub

Page 45: Building Single-Page Web Appplications in dart - Devoxx France 2013

Pub - pubspec.yaml

name: pacifista_rocksdescription: The best application in the whole worldversion: 0.0.1dependencies: great_lib: any

Page 46: Building Single-Page Web Appplications in dart - Devoxx France 2013

dartdoc

/// This is a single-line documentation comment.

/** * This is a multi-line documentation comment. * To generate the documentation: * $ dartdoc <filename> */void main() { }

Page 47: Building Single-Page Web Appplications in dart - Devoxx France 2013

dartdoc

Page 48: Building Single-Page Web Appplications in dart - Devoxx France 2013

Uses

•Single-page Web Apps

•Client and server side applications

•HTML Games

Page 49: Building Single-Page Web Appplications in dart - Devoxx France 2013

27 au 29 mars 2013

Démonstration

https://github.com/yohanbeschi/devoxxfr_20130327.dart

https://github.com/yohanbeschi/pwt_proto.dart

Page 50: Building Single-Page Web Appplications in dart - Devoxx France 2013

Roadmap

Today: M3

??: M4 Summer 2013 : V1 !

Page 51: Building Single-Page Web Appplications in dart - Devoxx France 2013

Want to know more ?

• DartLangFR

• Mailing-list : dartlangfr (https://groups.google.com/forum/?fromgroups=&hl=en#!forum/dartlangfr)

• Google+ : DartlangFR (https://plus.google.com/u/0/communities/104813951711720144450)

• Twitter : @dartlang_fr

• Blog : dartlangfr.net

• DartLang

• Site officiel : www.dartlang.org

• Mailing-list : dartlang (https://groups.google.com/a/dartlang.org/forum/?fromgroups&hl=en#!forum/misc)

• Google+ : Dart (https://plus.google.com/+dartlang)

• Google+ : Dartisans (https://plus.google.com/communities/114566943291919232850)

• Twitter : @dart_lang

• Blog : blog.dartwatch.com

• Newsletter : Dart weekly

Page 52: Building Single-Page Web Appplications in dart - Devoxx France 2013

Thanks

Questions ?