从 erlang 到 cerl 到 golang

32
从 Erlang 从 CERL 从 Go lang 从从从 [email protected] 2011-10-15

Upload: toby

Post on 22-Jan-2016

288 views

Category:

Documents


0 download

DESCRIPTION

从 Erlang 到 CERL 到 Golang. 许式伟 [email protected] 2011-10-15. 内容概要. 历史 Erlang => CERL => Golang Erlang CERL Golang QBox (Q盘). 历史:ECUG 议题. Erlang 2007: 我为什么选择了Erlang? 2008: Erlang 与 Comet Programming CERL 2009: CERL: 谈谈“Boost.ASIO、Erlang与服务器编程” 2010: 架构之美 & 软件质量保障 Golang - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 从 Erlang 到 CERL 到 Golang

从 Erlang 到 CERL 到 Golang

许式伟xushiweiqboxnet

2011-10-15

内容概要bull 历史

ndash Erlang =gt CERL =gt Golang

bull Erlang

bull CERL

bull Golang

bull QBox (Q 盘 )

历史 ECUG 议题bull Erlang

ndash 2007 我为什么选择了 Erlang ndash 2008 Erlang 与 Comet Programming

bull CERLndash 2009 CERL 谈谈ldquo BoostASIO Erlang 与

服务器编程rdquondash 2010 架构之美 amp 软件质量保障

bull Golangndash 2011 从 Erlang 到 CERL 到 Golang

历史我为什么选择了 Erlang bull Erlang 的优势

ndash Erlang 解放的是程序员在并行处理上的困扰这比内存管理的复杂度更大

ndash 面向并发编程 (OCP)ndash 错误处理哲学 速错 (Fail fast)

历史我为什么选择了 Erlang bull Erlang 的瓶颈 ( 困难之处 )

ndash 并行思维模式bull 尽管 Erlang 程序可以很方便地并行 分布式 但是

这并不意味着并行思维模式不需要被理解和掌握ndash 缺乏深入人心的 FP 编程理论

bull 没有 FPldquo 数据结构rdquo学大学的数据结构课程 都是基于命令式语言的

ndash 需要更高的培训成本bull 由于 FP 没有深入人心 Erlang 亦仍然属于小众 语言故

此培训成本较高

CERL

bull 最初语义ndash Erlang Model for C++ndash Erlang Style Concurrency ( Erlang 风格的并

发模型)在传统语言中的实施bull CERL 20

ndash 编程范式与 Erlang Style Concurrency 有很大的差异更接近于主流语言的编程范式

ndash 更多资料参阅bull httpecugorgcerl

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 2: 从 Erlang 到 CERL 到 Golang

内容概要bull 历史

ndash Erlang =gt CERL =gt Golang

bull Erlang

bull CERL

bull Golang

bull QBox (Q 盘 )

历史 ECUG 议题bull Erlang

ndash 2007 我为什么选择了 Erlang ndash 2008 Erlang 与 Comet Programming

bull CERLndash 2009 CERL 谈谈ldquo BoostASIO Erlang 与

服务器编程rdquondash 2010 架构之美 amp 软件质量保障

bull Golangndash 2011 从 Erlang 到 CERL 到 Golang

历史我为什么选择了 Erlang bull Erlang 的优势

ndash Erlang 解放的是程序员在并行处理上的困扰这比内存管理的复杂度更大

ndash 面向并发编程 (OCP)ndash 错误处理哲学 速错 (Fail fast)

历史我为什么选择了 Erlang bull Erlang 的瓶颈 ( 困难之处 )

ndash 并行思维模式bull 尽管 Erlang 程序可以很方便地并行 分布式 但是

这并不意味着并行思维模式不需要被理解和掌握ndash 缺乏深入人心的 FP 编程理论

bull 没有 FPldquo 数据结构rdquo学大学的数据结构课程 都是基于命令式语言的

ndash 需要更高的培训成本bull 由于 FP 没有深入人心 Erlang 亦仍然属于小众 语言故

此培训成本较高

CERL

bull 最初语义ndash Erlang Model for C++ndash Erlang Style Concurrency ( Erlang 风格的并

发模型)在传统语言中的实施bull CERL 20

ndash 编程范式与 Erlang Style Concurrency 有很大的差异更接近于主流语言的编程范式

ndash 更多资料参阅bull httpecugorgcerl

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 3: 从 Erlang 到 CERL 到 Golang

历史 ECUG 议题bull Erlang

ndash 2007 我为什么选择了 Erlang ndash 2008 Erlang 与 Comet Programming

bull CERLndash 2009 CERL 谈谈ldquo BoostASIO Erlang 与

服务器编程rdquondash 2010 架构之美 amp 软件质量保障

bull Golangndash 2011 从 Erlang 到 CERL 到 Golang

历史我为什么选择了 Erlang bull Erlang 的优势

ndash Erlang 解放的是程序员在并行处理上的困扰这比内存管理的复杂度更大

ndash 面向并发编程 (OCP)ndash 错误处理哲学 速错 (Fail fast)

历史我为什么选择了 Erlang bull Erlang 的瓶颈 ( 困难之处 )

ndash 并行思维模式bull 尽管 Erlang 程序可以很方便地并行 分布式 但是

这并不意味着并行思维模式不需要被理解和掌握ndash 缺乏深入人心的 FP 编程理论

bull 没有 FPldquo 数据结构rdquo学大学的数据结构课程 都是基于命令式语言的

ndash 需要更高的培训成本bull 由于 FP 没有深入人心 Erlang 亦仍然属于小众 语言故

此培训成本较高

CERL

bull 最初语义ndash Erlang Model for C++ndash Erlang Style Concurrency ( Erlang 风格的并

发模型)在传统语言中的实施bull CERL 20

ndash 编程范式与 Erlang Style Concurrency 有很大的差异更接近于主流语言的编程范式

ndash 更多资料参阅bull httpecugorgcerl

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 4: 从 Erlang 到 CERL 到 Golang

历史我为什么选择了 Erlang bull Erlang 的优势

ndash Erlang 解放的是程序员在并行处理上的困扰这比内存管理的复杂度更大

ndash 面向并发编程 (OCP)ndash 错误处理哲学 速错 (Fail fast)

历史我为什么选择了 Erlang bull Erlang 的瓶颈 ( 困难之处 )

ndash 并行思维模式bull 尽管 Erlang 程序可以很方便地并行 分布式 但是

这并不意味着并行思维模式不需要被理解和掌握ndash 缺乏深入人心的 FP 编程理论

bull 没有 FPldquo 数据结构rdquo学大学的数据结构课程 都是基于命令式语言的

ndash 需要更高的培训成本bull 由于 FP 没有深入人心 Erlang 亦仍然属于小众 语言故

此培训成本较高

CERL

bull 最初语义ndash Erlang Model for C++ndash Erlang Style Concurrency ( Erlang 风格的并

发模型)在传统语言中的实施bull CERL 20

ndash 编程范式与 Erlang Style Concurrency 有很大的差异更接近于主流语言的编程范式

ndash 更多资料参阅bull httpecugorgcerl

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 5: 从 Erlang 到 CERL 到 Golang

历史我为什么选择了 Erlang bull Erlang 的瓶颈 ( 困难之处 )

ndash 并行思维模式bull 尽管 Erlang 程序可以很方便地并行 分布式 但是

这并不意味着并行思维模式不需要被理解和掌握ndash 缺乏深入人心的 FP 编程理论

bull 没有 FPldquo 数据结构rdquo学大学的数据结构课程 都是基于命令式语言的

ndash 需要更高的培训成本bull 由于 FP 没有深入人心 Erlang 亦仍然属于小众 语言故

此培训成本较高

CERL

bull 最初语义ndash Erlang Model for C++ndash Erlang Style Concurrency ( Erlang 风格的并

发模型)在传统语言中的实施bull CERL 20

ndash 编程范式与 Erlang Style Concurrency 有很大的差异更接近于主流语言的编程范式

ndash 更多资料参阅bull httpecugorgcerl

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 6: 从 Erlang 到 CERL 到 Golang

CERL

bull 最初语义ndash Erlang Model for C++ndash Erlang Style Concurrency ( Erlang 风格的并

发模型)在传统语言中的实施bull CERL 20

ndash 编程范式与 Erlang Style Concurrency 有很大的差异更接近于主流语言的编程范式

ndash 更多资料参阅bull httpecugorgcerl

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 7: 从 Erlang 到 CERL 到 Golang

CERL 20

bull 轻量级进程进程间用消息传递通信ndash 同 Erlang Style Concurrencyndash 同 Golang

bull 进程间通过 MQ ( Channel )通信ndash 无进程邮箱(不同于 Erlang )ndash 同 Golang

bull SocketFile IO 与轻量级进程完美结合ndash 同 Golang 任何进程的 IO 不阻塞其他进程

bull Message 是二等公民 Selective receive 是浮云ndash 同 Golang 具体的网络协议可任意定制ndash 在 Erlang 中 Erlang Message amp Selective receive 是一等

公民 SocketFile IO 基于其实现

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 8: 从 Erlang 到 CERL 到 Golang

CERL - SDL 文法 vs Go

bull 类型定义ndash SDL type AliasType = RealTypendash Go type AliasType RealTypendash SDL 支持条件类型

bull 一种任何语言中都没有的类型bull 函数定义

ndash SDLbull [id=1] get(KeyT key) -gt ok ValueT value | false

ndash Gobull func Get(key KeyT) (ok bool value ValueT)

bull 更多关于 SDL 的资料ndash httpecugorgsdl

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 9: 从 Erlang 到 CERL 到 Golang

CERL 20

bull CERL 20 是雏形版的 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 10: 从 Erlang 到 CERL 到 Golang

Golang

bull 类型系统 (type system)

bull 内存管理 (memory management)

bull 接口 (interface)

bull 错误处理 (error processing)

bull 进程 (process)

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 11: 从 Erlang 到 CERL 到 Golang

类型系统 (type system)

bull C++ndash 理念只要愿意我们可以自己做一个 interfac

e 与内置类型一样的 User Type bull Java

ndash 理念 User Type 都是 Object 类型你需要注意这个世界有 2 套完全不同的类型体系

bull Golangndash 理念除了我们不推荐操作符重载外 User T

ype 与内置类型没有任何区别

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 12: 从 Erlang 到 CERL 到 Golang

类型系统 (type system) - C++class Intprivate int m_nValpublic Intamp assign(const Intamp r) this-gtm_nVal = rm_nVal return this

翻译成 C

struct Int int m_nVal

Int Int_assign(Int this const Int r) this-gtm_nVal = r-gtm_nVal return this

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 13: 从 Erlang 到 CERL 到 Golang

类型系统 (type system) - Gotype Int int

func (this Int) assign(r Int) Int this = r return this

翻译成 C

typedef int Int

Int Int_assign(Int this Int r) this = r return this

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 14: 从 Erlang 到 CERL 到 Golang

类型系统 (type system)

bull 没有隐式的类型转换 (auto typecast)

bull 没有重载 (overload)

bull 没有继承只有组合ndash 用ldquo匿名组合rdquo可以部分达到继承的效果

bull 没有虚函数 (virtual function)ndash 自然也就没有 override

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 15: 从 Erlang 到 CERL 到 Golang

类型组合的样例type Foo func (r Foo) foo()

type Bar func (r Bar) bar()

type Other func (r Other) dosth()

type Example Foo Bar other Other

var o Exampleofoo()obar()ootherdosth()

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 16: 从 Erlang 到 CERL 到 Golang

内存管理 (memory management)

bull C++ndash栈局部变量ndash堆 newdelete mallocfree

bull Javandash栈局部变量ndash堆 new GC

bull Gondash透明语言自动选择何时使用栈何时使用堆ndash GC

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 17: 从 Erlang 到 CERL 到 Golang

内存管理 - C++

void f1() Foo foo = new Foo

void f2() Foo foo

注 f1 中的 foo 分配在堆上 f2 中的 foo 分配在栈上

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 18: 从 Erlang 到 CERL 到 Golang

内存管理 - Golang

func f1() foo = ampFoo

func f2() foo = Foo

bull 注没有任何证据可以用来证明 f1 的 foo 分配在堆上 f2 的 foo 分配在栈上

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 19: 从 Erlang 到 CERL 到 Golang

接口 (interface)

bull C++ Java etcndash侵入式接口

bull Golangndash非侵入性接口

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 20: 从 Erlang 到 CERL 到 Golang

接口 (interface) - 侵入式interface Reader int Read(void buf int n)

interface Reader2 int Read(void buf int n)

class File public Reader int Read(void buf int n)

bull File 满足接口 Reader 但不满足 Reader2 尽管两者实际上是一样的 File 需要知道它准备实现哪个接口

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 21: 从 Erlang 到 CERL 到 Golang

接口 (interface) - 非侵入式interface Reader Read(buf []byte) (n int err osError)

interface Reader2 Read(buf []byte) (n int err osError)

type File struct

func (r File) Read(buf []byte) (n int err osError)

bull File 满足接口 Reader 也满足 Reader2 File 的实现并不需要知道接口 Reader 或者 Reader2

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 22: 从 Erlang 到 CERL 到 Golang

非侵入式接口bull 好处

ndash代码解耦ndash 在 Go 里面 interface 是按需定义无需事先

进行 ldquo统筹rdquo

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 23: 从 Erlang 到 CERL 到 Golang

非侵入式接口内部实现bull 有人感兴趣么

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 24: 从 Erlang 到 CERL 到 Golang

错误处理 (error processing)

bull C++ndash try catchndash句柄类 智能指针 (利用析构行为 )

bull Javandash try catchfinally

bull Gondash defer

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 25: 从 Erlang 到 CERL 到 Golang

错误处理 - C++Java

FILE fp = NULLtry fp = fopen() if (fp == NULL) return finally if (fp = NULL) fclose(fp)

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 26: 从 Erlang 到 CERL 到 Golang

错误处理 - Go

f err = osOpen()

if err = nil return

defer fClose()

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 27: 从 Erlang 到 CERL 到 Golang

进程 (process)

bull C++ndash 进程 Thread Fiberndash 进程通信没有标准的 Message Queue

bull Golangndash 进程 goroutinendash 进程通信 channel

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 28: 从 Erlang 到 CERL 到 Golang

进程 (process) - C++class Worker Worker(int a string b MQ mq) void run() this-gtm_mqPush(result)

static void ThreadProc(void param) Worker worker = (Worker)param worker-gtrun() delete worker

void caller() MQ mq = new MQ CreateThread(ThreadProc new Worker(1 hello mq)) result = mqPop() delete mq

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 29: 从 Erlang 到 CERL 到 Golang

进程 (process) - Go

func worker(a int b string mq chan ResultType)

mq lt- result

func caller() mq = make(chan ResultType) go worker(1 hello mq) result = lt-mq

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 30: 从 Erlang 到 CERL 到 Golang

Golang 的风险与建议bull 历史积累

ndash 如果团队已经有较多的代码积累不建议换 Go 来重写一遍ndash 新模块可尝试 Go 但是需要考虑跨语言调用带来的额外负担

bull 开发 Windows 桌面手机应用ndash Go 语言目前主要面向服务端开发不推荐应用于客户端开发领域

bull Golang 仍然在快速迭代变化ndash 尽管已经可用但 Golang 仍然在快速演变语言细节可能变更特别是库可能承受较大的演变

ndash 团队需要预见此风险并进行风险防范bull Golang 的社区仍然小众

ndash 人员招聘和培训成本较其他语言高

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 31: 从 Erlang 到 CERL 到 Golang

QBox (Q 盘 )

bull httpsqboxmendash专注于云存储领域的存储服务提供商

bull 服务端 99 代码基于 Golang

bull 累计约 10w 行 Golang 代码

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 32: 从 Erlang 到 CERL 到 Golang

Q amp Axushiweiqboxnet

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32