Dart 编程语言简介
        @yinhm

        TechParty


   February 25, 2012




     @yinhm   Dart   1/27
Dart: Structured Web
    Programming




       @yinhm   Dart   2/27
Dart 之新


• 新的编程语言




           @yinhm   Dart   3/27
Dart 之新


• 新的编程语言
• 新的开发工具




           @yinhm   Dart   3/27
Dart 之新


• 新的编程语言
• 新的开发工具
• 新的库




           @yinhm   Dart   3/27
Dart 之新


• 新的编程语言
• 新的开发工具
• 新的库
• 开源
   • 2011 年 10 月公开预览版
   • Dart 规范:0.07 草案




                 @yinhm   Dart   3/27
Dart 开发团队和社区生态


• Lars Bak:V8 引擎作者




                @yinhm   Dart   4/27
Dart 开发团队和社区生态


• Lars Bak:V8 引擎作者
• Gilad Bracha:第二、三版 JAVA 规范作者之一




                @yinhm   Dart   4/27
Dart 开发团队和社区生态


• Lars Bak:V8 引擎作者
• Gilad Bracha:第二、三版 JAVA 规范作者之一
• 80+ Google 工程师,部分来自 GWT 团队




                @yinhm   Dart   4/27
Dart 开发团队和社区生态


• Lars Bak:V8 引擎作者
• Gilad Bracha:第二、三版 JAVA 规范作者之一
• 80+ Google 工程师,部分来自 GWT 团队
• 少量社区成员




                @yinhm   Dart   4/27
Dart 开发团队和社区生态


• Lars Bak:V8 引擎作者
• Gilad Bracha:第二、三版 JAVA 规范作者之一
• 80+ Google 工程师,部分来自 GWT 团队
• 少量社区成员
• 讨论组:1055 成员,非常活跃




                @yinhm   Dart   4/27
Web 开发现状之弊端




   @yinhm   Dart   5/27
Dart 目标:结构化且灵活的 Web
        编程语言




       @yinhm   Dart   6/27
Dart 目标:易学,对程序员来说
      是熟悉且自然的




      @yinhm   Dart   7/27
Dart 目标:高性能、快启动




     @yinhm   Dart   8/27
Dart 目标:适合 Web 上的各类设
          备




        @yinhm   Dart   9/27
Dart 目标:各种主流浏览器支持




      @yinhm   Dart   10/27
Dart 编程语言




  @yinhm   Dart   11/27
Dart 编程语言


  简单无惊讶的面向对象编程语言
• Class、Interface




                    @yinhm   Dart   12/27
Dart 编程语言


  简单无惊讶的面向对象编程语言
• Class、Interface
• 可选静态类型




                    @yinhm   Dart   12/27
Dart 编程语言


  简单无惊讶的面向对象编程语言
• Class、Interface
• 可选静态类型
• Isolates




                    @yinhm   Dart   12/27
Dart 编程语言


  简单无惊讶的面向对象编程语言
• Class、Interface
• 可选静态类型
• Isolates
• Single-threaded
• first class functions




                         @yinhm   Dart   12/27
传承


• 面向对象受 Smalltalk 启发




                @yinhm   Dart   13/27
传承


• 面向对象受 Smalltalk 启发
• JIT 受 Self 启发




                  @yinhm   Dart   13/27
传承


• 面向对象受 Smalltalk 启发
• JIT 受 Self 启发
• 可选类型受 Strongtalk 启发




                  @yinhm   Dart   13/27
传承


• 面向对象受 Smalltalk 启发
• JIT 受 Self 启发
• 可选类型受 Strongtalk 启发
• Isolates 设计受 Erlang 影响




                   @yinhm   Dart   13/27
传承


• 面向对象受 Smalltalk 启发
• JIT 受 Self 启发
• 可选类型受 Strongtalk 启发
• Isolates 设计受 Erlang 影响
• 语法接近 JavaScript C




                   @yinhm   Dart   13/27
可选类型


• 动态类型,类似 JavaScript




                @yinhm   Dart   14/27
可选类型


• 动态类型,类似 JavaScript
• 静态类型
   • 不导致程序编译或运行失败(除非开发时设置为 checked 模
     式)
   • 提高易读性
   • 机器友好:IDE 补全,效验
   • 更早检测到错误




              @yinhm   Dart   14/27
可选类型


• 动态类型,类似 JavaScript
• 静态类型
   • 不导致程序编译或运行失败(除非开发时设置为 checked 模
     式)
   • 提高易读性
   • 机器友好:IDE 补全,效验
   • 更早检测到错误




              @yinhm   Dart   14/27
来点代码




@yinhm   Dart   15/27
Classes and interfaces
i n t e r f a c e Shape {
   num p e r i m e t e r ( ) ;
}

c l a s s R e c t a n g l e i m p l e m e n t s Shape {
    f i n a l num h e i g h t , w i d t h ;
    R e c t a n g l e (num t h i s . h e i g h t , num t h i s . w i d t h ) ;
// Compact c o n s t r u c t o r s y n t a x .
    num p e r i m e t e r ( ) => 2* h e i g h t + 2* w i d t h ;
// S h o r t f u n c t i o n s y n t a x .
}

c l a s s Square extends Rectangle {
    S q u a r e (num s i z e ) : s u p e r ( s i z e , s i z e ) ;
}

                                 @yinhm    Dart   16/27
Optional types

c l a s s Point {
    var x , y ;
    Point ( t h i s . x , t h i s . y ) ;
    s c a l e ( f a c t o r ) => new P o i n t ( x * f a c t o r , y * f a c t o r ) ;
    d i s t a n c e ( ) => Math . s q r t ( x * x + y * y ) ;
}

main ( ) {
  v a r a = new P o i n t ( 2 , 3 ) . s c a l e ( 1 0 ) ;
  print (a . distance ());
}




                                 @yinhm    Dart   17/27
Static types

c l a s s Point {
    num x , y ;
    P o i n t (num t h i s . x , num t h i s . y ) ;
    P o i n t s c a l e (num f a c t o r ) => new P o i n t ( x * f a c t o r , y *
    num d i s t a n c e ( ) => Math . s q r t ( x * x + y * y ) ;
}

v o i d main ( ) {
    P o i n t a = new P o i n t ( 2 , 3 ) . s c a l e ( 1 0 ) ;
    print (a . distance ());
}




                                @yinhm    Dart   18/27
如何使用?




 @yinhm   Dart   19/27
推荐:编译成 JavaScript 方式

      sdk/bin/frogc test.dart




           @yinhm   Dart   20/27
Dashboard

http://try.dartlang.org/




      @yinhm   Dart   21/27
Dart VM

sdk/bin/dart test.dart




    @yinhm   Dart   22/27
浏览器运行,可回退至 JS
MIME type: application/dart

 http://www.dartlang.org/dartium/index.html




                @yinhm   Dart   23/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap
   • Comparable: Date, Duration, String




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap
   • Comparable: Date, Duration, String
   • Hashable: num, String




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap
   • Comparable: Date, Duration, String
   • Hashable: num, String
   • Pattern: String, RegExp




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap
   • Comparable: Date, Duration, String
   • Hashable: num, String
   • Pattern: String, RegExp

• core 实现:Array, Collections, EventLoop...




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap
   • Comparable: Date, Duration, String
   • Hashable: num, String
   • Pattern: String, RegExp

• core 实现:Array, Collections, EventLoop...
• dom, html




                         @yinhm   Dart   24/27
自带库

• Dart Core 常见数据结构接口
   • Iterable, Collection:, List, Set, Queue
   • Map: HashMap, LinkedHashMap
   • Comparable: Date, Duration, String
   • Hashable: num, String
   • Pattern: String, RegExp

• core 实现:Array, Collections, EventLoop...
• dom, html
• io, json




                         @yinhm   Dart   24/27
Questions?




  @yinhm   Dart   25/27
Links


• Dart 官网: http://www.dartlang.org/
• Intro to Dart
• Dart: a new programming language for structured web
• A Walk on the Dart Side
• Dart Technical Overview




                       @yinhm   Dart   26/27
About


        Created in L TEX using the beamer class, TeX Live and Emacs.
                   A



        Published under the Creative Commons Attribution 3.0 License
              http://creativecommons.org/licenses/by/3.0/

                                by @yinhm
                        http://yinhm.appspot.com


                    Document version February 25, 2012




                           @yinhm        Dart    27/27

Dart intro

  • 1.
    Dart 编程语言简介 @yinhm TechParty February 25, 2012 @yinhm Dart 1/27
  • 2.
    Dart: Structured Web Programming @yinhm Dart 2/27
  • 3.
  • 4.
    Dart 之新 • 新的编程语言 •新的开发工具 @yinhm Dart 3/27
  • 5.
    Dart 之新 • 新的编程语言 •新的开发工具 • 新的库 @yinhm Dart 3/27
  • 6.
    Dart 之新 • 新的编程语言 •新的开发工具 • 新的库 • 开源 • 2011 年 10 月公开预览版 • Dart 规范:0.07 草案 @yinhm Dart 3/27
  • 7.
    Dart 开发团队和社区生态 • LarsBak:V8 引擎作者 @yinhm Dart 4/27
  • 8.
    Dart 开发团队和社区生态 • LarsBak:V8 引擎作者 • Gilad Bracha:第二、三版 JAVA 规范作者之一 @yinhm Dart 4/27
  • 9.
    Dart 开发团队和社区生态 • LarsBak:V8 引擎作者 • Gilad Bracha:第二、三版 JAVA 规范作者之一 • 80+ Google 工程师,部分来自 GWT 团队 @yinhm Dart 4/27
  • 10.
    Dart 开发团队和社区生态 • LarsBak:V8 引擎作者 • Gilad Bracha:第二、三版 JAVA 规范作者之一 • 80+ Google 工程师,部分来自 GWT 团队 • 少量社区成员 @yinhm Dart 4/27
  • 11.
    Dart 开发团队和社区生态 • LarsBak:V8 引擎作者 • Gilad Bracha:第二、三版 JAVA 规范作者之一 • 80+ Google 工程师,部分来自 GWT 团队 • 少量社区成员 • 讨论组:1055 成员,非常活跃 @yinhm Dart 4/27
  • 12.
  • 13.
    Dart 目标:结构化且灵活的 Web 编程语言 @yinhm Dart 6/27
  • 14.
    Dart 目标:易学,对程序员来说 是熟悉且自然的 @yinhm Dart 7/27
  • 15.
  • 16.
    Dart 目标:适合 Web上的各类设 备 @yinhm Dart 9/27
  • 17.
  • 18.
    Dart 编程语言 @yinhm Dart 11/27
  • 19.
    Dart 编程语言 简单无惊讶的面向对象编程语言 • Class、Interface @yinhm Dart 12/27
  • 20.
    Dart 编程语言 简单无惊讶的面向对象编程语言 • Class、Interface • 可选静态类型 @yinhm Dart 12/27
  • 21.
    Dart 编程语言 简单无惊讶的面向对象编程语言 • Class、Interface • 可选静态类型 • Isolates @yinhm Dart 12/27
  • 22.
    Dart 编程语言 简单无惊讶的面向对象编程语言 • Class、Interface • 可选静态类型 • Isolates • Single-threaded • first class functions @yinhm Dart 12/27
  • 23.
    传承 • 面向对象受 Smalltalk启发 @yinhm Dart 13/27
  • 24.
    传承 • 面向对象受 Smalltalk启发 • JIT 受 Self 启发 @yinhm Dart 13/27
  • 25.
    传承 • 面向对象受 Smalltalk启发 • JIT 受 Self 启发 • 可选类型受 Strongtalk 启发 @yinhm Dart 13/27
  • 26.
    传承 • 面向对象受 Smalltalk启发 • JIT 受 Self 启发 • 可选类型受 Strongtalk 启发 • Isolates 设计受 Erlang 影响 @yinhm Dart 13/27
  • 27.
    传承 • 面向对象受 Smalltalk启发 • JIT 受 Self 启发 • 可选类型受 Strongtalk 启发 • Isolates 设计受 Erlang 影响 • 语法接近 JavaScript C @yinhm Dart 13/27
  • 28.
  • 29.
    可选类型 • 动态类型,类似 JavaScript •静态类型 • 不导致程序编译或运行失败(除非开发时设置为 checked 模 式) • 提高易读性 • 机器友好:IDE 补全,效验 • 更早检测到错误 @yinhm Dart 14/27
  • 30.
    可选类型 • 动态类型,类似 JavaScript •静态类型 • 不导致程序编译或运行失败(除非开发时设置为 checked 模 式) • 提高易读性 • 机器友好:IDE 补全,效验 • 更早检测到错误 @yinhm Dart 14/27
  • 31.
  • 32.
    Classes and interfaces in t e r f a c e Shape { num p e r i m e t e r ( ) ; } c l a s s R e c t a n g l e i m p l e m e n t s Shape { f i n a l num h e i g h t , w i d t h ; R e c t a n g l e (num t h i s . h e i g h t , num t h i s . w i d t h ) ; // Compact c o n s t r u c t o r s y n t a x . num p e r i m e t e r ( ) => 2* h e i g h t + 2* w i d t h ; // S h o r t f u n c t i o n s y n t a x . } c l a s s Square extends Rectangle { S q u a r e (num s i z e ) : s u p e r ( s i z e , s i z e ) ; } @yinhm Dart 16/27
  • 33.
    Optional types c la s s Point { var x , y ; Point ( t h i s . x , t h i s . y ) ; s c a l e ( f a c t o r ) => new P o i n t ( x * f a c t o r , y * f a c t o r ) ; d i s t a n c e ( ) => Math . s q r t ( x * x + y * y ) ; } main ( ) { v a r a = new P o i n t ( 2 , 3 ) . s c a l e ( 1 0 ) ; print (a . distance ()); } @yinhm Dart 17/27
  • 34.
    Static types c la s s Point { num x , y ; P o i n t (num t h i s . x , num t h i s . y ) ; P o i n t s c a l e (num f a c t o r ) => new P o i n t ( x * f a c t o r , y * num d i s t a n c e ( ) => Math . s q r t ( x * x + y * y ) ; } v o i d main ( ) { P o i n t a = new P o i n t ( 2 , 3 ) . s c a l e ( 1 0 ) ; print (a . distance ()); } @yinhm Dart 18/27
  • 35.
  • 36.
    推荐:编译成 JavaScript 方式 sdk/bin/frogc test.dart @yinhm Dart 20/27
  • 37.
  • 38.
  • 39.
    浏览器运行,可回退至 JS MIME type:application/dart http://www.dartlang.org/dartium/index.html @yinhm Dart 23/27
  • 40.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue @yinhm Dart 24/27
  • 41.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap @yinhm Dart 24/27
  • 42.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap • Comparable: Date, Duration, String @yinhm Dart 24/27
  • 43.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap • Comparable: Date, Duration, String • Hashable: num, String @yinhm Dart 24/27
  • 44.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap • Comparable: Date, Duration, String • Hashable: num, String • Pattern: String, RegExp @yinhm Dart 24/27
  • 45.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap • Comparable: Date, Duration, String • Hashable: num, String • Pattern: String, RegExp • core 实现:Array, Collections, EventLoop... @yinhm Dart 24/27
  • 46.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap • Comparable: Date, Duration, String • Hashable: num, String • Pattern: String, RegExp • core 实现:Array, Collections, EventLoop... • dom, html @yinhm Dart 24/27
  • 47.
    自带库 • Dart Core常见数据结构接口 • Iterable, Collection:, List, Set, Queue • Map: HashMap, LinkedHashMap • Comparable: Date, Duration, String • Hashable: num, String • Pattern: String, RegExp • core 实现:Array, Collections, EventLoop... • dom, html • io, json @yinhm Dart 24/27
  • 48.
    Questions? @yinhm Dart 25/27
  • 49.
    Links • Dart 官网:http://www.dartlang.org/ • Intro to Dart • Dart: a new programming language for structured web • A Walk on the Dart Side • Dart Technical Overview @yinhm Dart 26/27
  • 50.
    About Created in L TEX using the beamer class, TeX Live and Emacs. A Published under the Creative Commons Attribution 3.0 License http://creativecommons.org/licenses/by/3.0/ by @yinhm http://yinhm.appspot.com Document version February 25, 2012 @yinhm Dart 27/27