SlideShare a Scribd company logo
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、   始使用
Golang
安装(通过源码)

$ 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命令进行包管理和构建

语法加亮

代码提示

保存时自动格式化代码
Golang
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

PDF
Introduce to Linux command line
PPTX
Golang 入門初體驗
PPT
Python 入门
PDF
shell script introduction
ODP
新北市教師工作坊 -- Bash script programming 介紹
PDF
Hello world 的一生
PPTX
Corona 初探 lua 語言,玩跨平台(iOS & android) 行動裝置開發工具
PDF
Mac os Terminal 常用指令與小技巧
Introduce to Linux command line
Golang 入門初體驗
Python 入门
shell script introduction
新北市教師工作坊 -- Bash script programming 介紹
Hello world 的一生
Corona 初探 lua 語言,玩跨平台(iOS & android) 行動裝置開發工具
Mac os Terminal 常用指令與小技巧

What's hot (13)

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

Viewers also liked (7)

KEY
Scala
PPTX
并发控制
PDF
Scala
PDF
Java并发核心编程
PPT
MongoDB介绍
PPTX
Big Data Analytics Infrastructure
PDF
Message Queues for Web Applications
Scala
并发控制
Scala
Java并发核心编程
MongoDB介绍
Big Data Analytics Infrastructure
Message Queues for Web Applications
Ad

Similar to Golang (12)

PDF
DOC
Go Lang
PPTX
Golangintro
PPT
Go语言: 互联网时代的C
PDF
模块一-Go语言特性.pdf
PPTX
Go语言学习指南
PDF
PDF
PPTX
Go for web
PDF
Go集成c&c++代码
PPTX
Go 語言基礎簡介
PDF
Introduction to Golang final
Go Lang
Golangintro
Go语言: 互联网时代的C
模块一-Go语言特性.pdf
Go语言学习指南
Go for web
Go集成c&c++代码
Go 語言基礎簡介
Introduction to Golang final

Golang

Editor's Notes