1 / 22

关于 Go 语言的思考

关于 Go 语言的思考. 韦光京 2011-10-29. 概要. 为什么喜欢 Go 语言 Go 语言的面向对象 Go 语言的动态 特性 Go 语言的并发特性 Go 语言的未来: Go 1 特别的: Go 语言的 windows 移植. 为什么喜欢 Go 语言. 向 Unix 致敬 Ken Thompson Rob Pike C + Python ,动静相宜. 为什么喜欢 Go 语言. 语法很特别,可读性强 从左往右读,写起来也很方便 X int func main(argc int, argv *[]byte) int

Télécharger la présentation

关于 Go 语言的思考

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 关于Go语言的思考 韦光京 2011-10-29

  2. 概要 • 为什么喜欢Go语言 • Go语言的面向对象 • Go语言的动态特性 • Go语言的并发特性 • Go语言的未来:Go 1 • 特别的:Go语言的windows移植

  3. 为什么喜欢Go语言 • 向Unix致敬 • Ken Thompson • Rob Pike • C + Python,动静相宜

  4. 为什么喜欢Go语言 • 语法很特别,可读性强 • 从左往右读,写起来也很方便 X int func main(argc int, argv *[]byte) int f func(func(int,int) int, int) int f func(func(int,int) int, int) func(int, int) int sum := func(a, b int) int { return a+b } (3, 4)

  5. 为什么喜欢Go语言 • Open source •  Bossie 2010 “best open source application development software.” 奖 • Codereview机制 • Just for fun

  6. 一些特别的地方 • 减少打字,自动类型推导 /* Define and use a type, T. */ type T struct { a, b int } var t0 *T = new(T) t1 := new(T) // type taken from expr

  7. 非常实用的工具 • Gofmt 格式化代码 • Gofix 自动更新代码 • Godoc 从Go代码中生成文档 • Gotest 测试框架 • Goinstall 下载并编译安装库

  8. 跨平台,交叉编译 • GOOS,GOARCH环境变量 • Linux,Windows,Mac,BSD,Plan 9 • X86,AMD64,ARM

  9. Google App Engine支持 • 目前是Experimental状态 • Go 1将会正式支持

  10. 没有类的面向对象机制 • 任何类型都可以有方法,任何类型都可以是对象 • Interface强制数据和代码分离(抽象类) • 继承通过嵌入来实现(Mix-in) • 冲突的简单处理

  11. 例子 type 动物 struct { 生命值 int } func (动物) 叫() string { return "" } type 猫 struct { 动物 } func (猫) 叫() string { return "喵喵" }

  12. 动态特性 • Duck typing • Interface定义方法集合 • 任何类型实现了这些方法就实现了这个interface

  13. 反射 • Interface {} • TypeOf • ValueOf • SetXXX

  14. 并发 • 语法级支持 • Goroutines • Channel timeout := make(chan bool, 1) go func() {time.Sleep(1e9) // one secondtimeout <- true }()

  15. 并发 • Channelis First class • Channel传递的消息可以是channel • 用同步的方式来简化并发编程 • Communicating Sequential Processes (CSP)

  16. A card reassembly example in Go • func copy(west, east chan byte) { for { east <- <-west } } • func assemble(X chan byte, printer chan []byte) { • lineimage := make([]byte, 125) • for i := 0;; { • lineimage[i] = <-X • if i < 124 { i++ } else { printer <- lineimage; i = 0 } • } • } • func disassemble(cardfile chan []byte, X chan byte) { • for { • cardimage := <-cardfile • i := 0 • for i < len(cardimage) { X <- cardimage[i]; i++ } • for i < 80 { X <- ' '; i++ } • } • } • go disassemble(cardreader, chars1) • go copy(chars1, chars2) • go assemble(chars2, lineprinter)

  17. Go的未来 • Go 1 • 计划在2012年初发布 • Go语言将迎来第一个稳定版本!

  18. 特别的:Go语言的Windows移植 • 32位(X86)、64位(AMD64)都已经完成 • 完整移植 • 编译器 • runtime • pkg • Cgo • Gdb调试 • 我们是英雄! • Alex Brainman, Hector Chu, Joe Poirier, 我….

  19. Windows的一些特性 • 链接PE object 文件 • 动态、静态链接 • 嵌入资源文件 • 可爱的图标 • 生成gui界面程序 • 控制台和GUI程序

  20. 我的未来的一些计划 • 支持生成动态库 • Gccgo的windows移植?

  21. 个人建议 • 投入Go语言的怀抱吧,重拾编程的乐趣!

  22. Q&A Vcc.163@gamil.com

More Related