SlideShare a Scribd company logo
1 of 43
Go语言入
        Sparkle
大纲

1、什么是Go

2、为什么我们要学习(使用)Go

3、语法特性

4、   始使用

5、缺点
1、什么是Go
什么是Go

Google于2009发布

TIOBE 2009年度语言

目前TIOBE排名50以外(吐槽)

系统级语言

并发语言
ECUG


Erlang China User Group

Effective Cloud User Group

ECUG Con 2011,国内第一场以 Go 语言为主题
的盛宴!
CERL 是我写的一个 C++ 程序库,取意于:Erlang For
C/C++。但最终其实 CERL 不是一个编程范式类似于
Erlang 的东西,而更象是一个雏形版本的 Golang。
                            ——许式伟
我发现我花了四年时间锤炼自己用 C 语言构建系统的
能力,试图找到一个规范,可以更好的编写软件。结果
      发现只是对 Go 的模仿。
                      ——云风
目前状态



Go1已经发布(第一个稳定版)
2、为什么我们要学习
只用一   语言的攻城师不
为什么是Go

多年Java经验

熟悉Python、Ruby、Scala

但觉得C/C++困难

Go语言让我有机会接近系统
Go特性

源自C(不是C++)

编译速度

gc

特殊的面向对象

简洁又   活的语法
3、语法特性
Hello, world!
package main

import "fmt"

func main() {
  fmt.Println("Hello, world!")
}
defer
func main() {
  file := os.Open("hello.txt")
  defer file.Close()

    // use file
}
错误
func main() {
	 file, err := os.Open("hello.txt")
	 if err != nil {
	 	 return
	}
	 defer file.Close()

	 // use file
}
常
func main() {
  defer func() {
    if r := recover(); r != nil {
      fmt.Println("recover", r)
    }
  }()

    someFunc()
}

func someFunc() {
  panic("[fail]")
}
没有类
type Vertex struct {
  X, Y float64
}

func (v *Vertex) Abs() float64 {
  return math.Sqrt(v.X*v.X + v.Y*v.Y)
}

func main() {
  v := &Vertex{3, 4}
  fmt.Println(v.Abs())
}
没有继承
type Egg struct {
	 weight int
}

type Animal struct {
	 weight int
}

type Bird struct {
	 Animal
	 egg Egg
}
接口
type Abser interface {
  Abs() float64
}

type MyFloat float64

func (f MyFloat) Abs() float64 {
  if f < 0 {
    return float64(-f)
  }
  return float64(f)
}
并发
为什么不用锁模型

锁的粒度不能太大

死锁问题

编程难度

面对越来越多的CPU
Scala介绍中提到
类线程行为
func main() {
  go myFunc()

    go func() {
      // code
    }()
}
类Actor行为
var ch = make(chan int)

func myActor() {
  data := <-ch
  // use data
}

func main() {
  go myActor()

    ch <- 1
}
纤程

同步代码   步效果

非抢占式

单线程实现

无线程切换,无锁

理论上可以无限个(内存限制)
类纤程行为
func myActor() {
  data := <-ch

    // some code

    time.Sleep(100)
    other := <-otherCh

    // use data
}
4、   始使用
安装(通过源码)

$ hg clone -u release https://code.google.com/p/go
$ cd go/src
$ ./all.bash
安装

http://code.google.com/p/go/downloads/list

有Linux Mac FreeBSD Windows的二进制版

brew install go

homebrew for Mac

GAE for Go
IDE



暂无完整IDE
可以不需要IDE,因为Go

构建

包管理

代码格式化

通过gocode提供代码提示
编辑器


Emacs

Vim

Sublime

甚至Notepad
Sublime+GoSublime
     +gocode

通过Go命令进行包管理和构建

语法加亮

代码提示

保存时自动格式化代码
Go命令


go get 安装第三方类库

go build 构建

go run hello.go 编译并且运行
GAE for Go

内置Go,直接使用

保存自动编译

不支持Windows

直接   始Web 发
学习资源
http://tour.golang.org/

http://golang.org/doc/

http://code.google.com/p/golang-china/

http://www.mikespook.com/

https://github.com/wonderfo/wonderfogo/wiki

许式伟《Go语言编程》
5、缺点
曾经的缺点


构建工具

IDE

windows支持
缺点

第三方类库

gc

多CPU支持

动态链接
谢谢


weibo&twitter: sparklezeng

email: popeast@gmail.com

website: http://weavesky.com

More Related Content

What's hot

Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern理 傅
 
如何学习Bash Shell
如何学习Bash Shell如何学习Bash Shell
如何学习Bash ShellLI Daobing
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享Yihua Huang
 
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for AndroidLight talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for AndroidKito Cheng
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)wang hongjiang
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典Tom Chen
 
Linux
LinuxLinux
Linuxlaihj
 
Effective linux.2.(tools)
Effective linux.2.(tools)Effective linux.2.(tools)
Effective linux.2.(tools)wang hongjiang
 
Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫Kito Cheng
 
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境均民 戴
 
4, grep
4, grep4, grep
4, grepted-xu
 

What's hot (13)

Zsh
ZshZsh
Zsh
 
Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern
 
如何学习Bash Shell
如何学习Bash Shell如何学习Bash Shell
如何学习Bash Shell
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享
 
Light talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for AndroidLight talk @ coscup 2011 : Incremental Global Prelink for Android
Light talk @ coscup 2011 : Incremental Global Prelink for Android
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典
 
Linux
LinuxLinux
Linux
 
Effective linux.2.(tools)
Effective linux.2.(tools)Effective linux.2.(tools)
Effective linux.2.(tools)
 
Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫Android C Library: Bionic 成長計畫
Android C Library: Bionic 成長計畫
 
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
 
Execution
ExecutionExecution
Execution
 
4, grep
4, grep4, grep
4, grep
 

Viewers also liked

Java并发核心编程
Java并发核心编程Java并发核心编程
Java并发核心编程wavefly
 
MongoDB介绍
MongoDB介绍MongoDB介绍
MongoDB介绍popeast
 
Big Data Analytics Infrastructure
Big Data Analytics InfrastructureBig Data Analytics Infrastructure
Big Data Analytics InfrastructureMin Zhou
 
Message Queues for Web Applications
Message Queues for Web ApplicationsMessage Queues for Web Applications
Message Queues for Web ApplicationsGareth Rushgrove
 

Viewers also liked (7)

Scala
ScalaScala
Scala
 
并发控制
并发控制并发控制
并发控制
 
Scala
ScalaScala
Scala
 
Java并发核心编程
Java并发核心编程Java并发核心编程
Java并发核心编程
 
MongoDB介绍
MongoDB介绍MongoDB介绍
MongoDB介绍
 
Big Data Analytics Infrastructure
Big Data Analytics InfrastructureBig Data Analytics Infrastructure
Big Data Analytics Infrastructure
 
Message Queues for Web Applications
Message Queues for Web ApplicationsMessage Queues for Web Applications
Message Queues for Web Applications
 

Similar to Golang

Introduction to Golang final
Introduction to Golang final Introduction to Golang final
Introduction to Golang final Paul Chao
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practicelitaocheng
 
Erlang jiacheng
Erlang jiachengErlang jiacheng
Erlang jiachengAir-Smile
 
Lucene 全文检索实践
Lucene 全文检索实践Lucene 全文检索实践
Lucene 全文检索实践yiditushe
 
Golangintro
GolangintroGolangintro
Golangintro理 傅
 
Go集成c&c++代码
Go集成c&c++代码Go集成c&c++代码
Go集成c&c++代码Andy Shi
 
2006 recycle opensourceprojects
2006 recycle opensourceprojects2006 recycle opensourceprojects
2006 recycle opensourceprojectsGeorge Ang
 
Recycle Open Source Projects
Recycle Open Source ProjectsRecycle Open Source Projects
Recycle Open Source ProjectsGeorge Ang
 
學好 node.js 不可不知的事
學好 node.js 不可不知的事學好 node.js 不可不知的事
學好 node.js 不可不知的事Ben Lue
 
《Java程序设计》期末考试试题 (六)
《Java程序设计》期末考试试题 (六)《Java程序设计》期末考试试题 (六)
《Java程序设计》期末考试试题 (六)jane2006
 
Groovy:Candy for Java Developers
Groovy:Candy for Java DevelopersGroovy:Candy for Java Developers
Groovy:Candy for Java Developersfoxgem
 
Go语言web开发
Go语言web开发Go语言web开发
Go语言web开发Andy Shi
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台Bo-Yi Wu
 
程式人雜誌 -- 2015 年5月號
程式人雜誌 -- 2015 年5月號程式人雜誌 -- 2015 年5月號
程式人雜誌 -- 2015 年5月號鍾誠 陳鍾誠
 
程式人雜誌 2015年五月
程式人雜誌 2015年五月程式人雜誌 2015年五月
程式人雜誌 2015年五月鍾誠 陳鍾誠
 
JCConf2015: groovy to gradle
 JCConf2015: groovy to gradle JCConf2015: groovy to gradle
JCConf2015: groovy to gradleChing Yi Chan
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introductionotakustay
 

Similar to Golang (20)

Introduction to Golang final
Introduction to Golang final Introduction to Golang final
Introduction to Golang final
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practice
 
Erlang jiacheng
Erlang jiachengErlang jiacheng
Erlang jiacheng
 
Lucene 全文检索实践
Lucene 全文检索实践Lucene 全文检索实践
Lucene 全文检索实践
 
Golangintro
GolangintroGolangintro
Golangintro
 
Go集成c&c++代码
Go集成c&c++代码Go集成c&c++代码
Go集成c&c++代码
 
2006 recycle opensourceprojects
2006 recycle opensourceprojects2006 recycle opensourceprojects
2006 recycle opensourceprojects
 
Recycle Open Source Projects
Recycle Open Source ProjectsRecycle Open Source Projects
Recycle Open Source Projects
 
學好 node.js 不可不知的事
學好 node.js 不可不知的事學好 node.js 不可不知的事
學好 node.js 不可不知的事
 
Php
PhpPhp
Php
 
《Java程序设计》期末考试试题 (六)
《Java程序设计》期末考试试题 (六)《Java程序设计》期末考试试题 (六)
《Java程序设计》期末考试试题 (六)
 
Groovy:Candy for Java Developers
Groovy:Candy for Java DevelopersGroovy:Candy for Java Developers
Groovy:Candy for Java Developers
 
Go语言web开发
Go语言web开发Go语言web开发
Go语言web开发
 
Gnu
GnuGnu
Gnu
 
gnutool
gnutoolgnutool
gnutool
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台
 
程式人雜誌 -- 2015 年5月號
程式人雜誌 -- 2015 年5月號程式人雜誌 -- 2015 年5月號
程式人雜誌 -- 2015 年5月號
 
程式人雜誌 2015年五月
程式人雜誌 2015年五月程式人雜誌 2015年五月
程式人雜誌 2015年五月
 
JCConf2015: groovy to gradle
 JCConf2015: groovy to gradle JCConf2015: groovy to gradle
JCConf2015: groovy to gradle
 
ES5 introduction
ES5 introductionES5 introduction
ES5 introduction
 

Golang

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n