Dart 编程语言简介 @yinhm TechParty February 25, 2012 @yinhm Dart 1/27
Dart编程语言简介@yinhm
TechParty
February 25, 2012
@yinhm Dart 1/27
Dart: Structured WebProgramming
@yinhm Dart 2/27
Dart之新
• 新的编程语言
• 新的开发工具• 新的库• 开源
• 2011年 10月公开预览版• Dart规范:0.07草案
@yinhm Dart 3/27
Dart之新
• 新的编程语言• 新的开发工具
• 新的库• 开源
• 2011年 10月公开预览版• Dart规范:0.07草案
@yinhm Dart 3/27
Dart之新
• 新的编程语言• 新的开发工具• 新的库
• 开源• 2011年 10月公开预览版• Dart规范:0.07草案
@yinhm Dart 3/27
Dart之新
• 新的编程语言• 新的开发工具• 新的库• 开源
• 2011年 10月公开预览版• Dart规范:0.07草案
@yinhm Dart 3/27
Dart 开发团队和社区生态
• Lars Bak:V8引擎作者
• Gilad Bracha:第二、三版 JAVA规范作者之一• 80+ Google工程师,部分来自 GWT团队• 少量社区成员• 讨论组:1055成员,非常活跃
@yinhm Dart 4/27
Dart 开发团队和社区生态
• Lars Bak:V8引擎作者• Gilad Bracha:第二、三版 JAVA规范作者之一
• 80+ Google工程师,部分来自 GWT团队• 少量社区成员• 讨论组:1055成员,非常活跃
@yinhm Dart 4/27
Dart 开发团队和社区生态
• Lars Bak:V8引擎作者• Gilad Bracha:第二、三版 JAVA规范作者之一• 80+ Google工程师,部分来自 GWT团队
• 少量社区成员• 讨论组:1055成员,非常活跃
@yinhm Dart 4/27
Dart 开发团队和社区生态
• Lars Bak:V8引擎作者• Gilad Bracha:第二、三版 JAVA规范作者之一• 80+ Google工程师,部分来自 GWT团队• 少量社区成员
• 讨论组:1055成员,非常活跃
@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
• 可选静态类型• Isolates• Single-threaded• first class functions
@yinhm Dart 12/27
Dart 编程语言
简单无惊讶的面向对象编程语言
• Class、Interface• 可选静态类型
• Isolates• Single-threaded• first class functions
@yinhm Dart 12/27
Dart 编程语言
简单无惊讶的面向对象编程语言
• Class、Interface• 可选静态类型• Isolates
• Single-threaded• first class functions
@yinhm Dart 12/27
Dart 编程语言
简单无惊讶的面向对象编程语言
• Class、Interface• 可选静态类型• Isolates• Single-threaded• first class functions
@yinhm Dart 12/27
传承
• 面向对象受 Smalltalk 启发
• JIT 受 Self 启发• 可选类型受 Strongtalk 启发• Isolates 设计受 Erlang 影响• 语法接近 JavaScript C
@yinhm Dart 13/27
传承
• 面向对象受 Smalltalk 启发• JIT 受 Self 启发
• 可选类型受 Strongtalk 启发• Isolates 设计受 Erlang 影响• 语法接近 JavaScript C
@yinhm Dart 13/27
传承
• 面向对象受 Smalltalk 启发• JIT 受 Self 启发• 可选类型受 Strongtalk 启发
• Isolates 设计受 Erlang 影响• 语法接近 JavaScript C
@yinhm Dart 13/27
传承
• 面向对象受 Smalltalk 启发• JIT 受 Self 启发• 可选类型受 Strongtalk 启发• Isolates 设计受 Erlang 影响
• 语法接近 JavaScript C
@yinhm Dart 13/27
传承
• 面向对象受 Smalltalk 启发• JIT 受 Self 启发• 可选类型受 Strongtalk 启发• Isolates 设计受 Erlang 影响• 语法接近 JavaScript C
@yinhm Dart 13/27
可选类型
• 动态类型,类似 JavaScript
• 静态类型• 不导致程序编译或运行失败(除非开发时设置为 checked模式)
• 提高易读性• 机器友好:IDE补全,效验• 更早检测到错误
@yinhm Dart 14/27
可选类型
• 动态类型,类似 JavaScript• 静态类型
• 不导致程序编译或运行失败(除非开发时设置为 checked模式)
• 提高易读性• 机器友好:IDE补全,效验• 更早检测到错误
@yinhm Dart 14/27
可选类型
• 动态类型,类似 JavaScript• 静态类型
• 不导致程序编译或运行失败(除非开发时设置为 checked模式)
• 提高易读性• 机器友好:IDE补全,效验• 更早检测到错误
@yinhm Dart 14/27
来点代码
@yinhm Dart 15/27
Classes and interfacesi n t e r f a c e Shape {
num pe r ime t e r ( ) ;}
c l a s s Rec tang l e implements Shape {f i n a l num he igh t , width ;Rec tang l e (num t h i s . he i gh t , num t h i s . w idth ) ;
// Compact c o n s t r u c t o r s yn tax .num pe r ime t e r ( ) => 2* he i g h t + 2*width ;
// Shor t f u n c t i o n s yn tax .}
c l a s s Square ex t end s Rec tang l e {Square (num s i z e ) : s upe r ( s i z e , s i z e ) ;
}
@yinhm Dart 16/27
Optional types
c l a s s Po in t {va r x , y ;Po in t ( t h i s . x , t h i s . y ) ;s c a l e ( f a c t o r ) => new Po in 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 ( ) {va r a = new Po in t ( 2 , 3 ) . s c a l e ( 1 0 ) ;p r i n t ( a . d i s t a n c e ( ) ) ;
}
@yinhm Dart 17/27
Static types
c l a s s Po in t {num x , y ;Po in t (num t h i s . x , num t h i s . y ) ;Po in t s c a l e (num f a c t o r ) => new Po in t ( x* f a c t o r , y* f a c t o r ) ;num d i s t a n c e ( ) => Math . s q r t ( x*x + y*y ) ;
}
vo i d main ( ) {Po in t a = new Po in t ( 2 , 3 ) . s c a l e ( 1 0 ) ;p r i n t ( a . d i s t a n c e ( ) ) ;
}
@yinhm Dart 18/27
如何使用?
@yinhm Dart 19/27
推荐:编译成 JavaScript方式
sdk/bin/frogc test.dart
@yinhm Dart 20/27
Dart VM
sdk/bin/dart test.dart
@yinhm Dart 22/27
浏览器运行,可回退至 JSMIME type: application/dart
http://www.dartlang.org/dartium/index.html
@yinhm Dart 23/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
自带库
• 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
自带库
• 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
自带库
• 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
自带库
• 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
自带库
• 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
自带库
• 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
自带库
• 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 LATEX using the beamer class, TeX Live and Emacs.
Published under the Creative Commons Attribution 3.0 Licensehttp://creativecommons.org/licenses/by/3.0/
by @yinhmhttp://yinhm.appspot.com
Document version February 25, 2012
@yinhm Dart 27/27