导读:从问题自己出发,不局限于 Go 语言,探讨服务器中经常遇到的问题,最后回到 Go 如何解决这些问题,为你们提供 Go 开发的关键技术指南。咱们将以系列文章的形式推出《Go 开发的关键技术指南》,共有 4 篇文章,本文为第 1 篇。
该指南主要讨论了服务器领域常见的并发问题,也涉及到了工程化相关的问题,还整理了 C 背景程序员对于 Go 的 GC 以及性能的疑问,探讨了 Go 的错误处理和类型系统最佳实践,以及依赖管理的难处、接口设计的正交性,固然也包含咱们在服务器开发中对于 Go 实践的总结,有时候也会对一些有趣的问题作深度的挖掘,列出了 Go 重要的事件和资料集合,以及 Go2 的进展和思考。html
如下是各个章节以及简介:git
The Go Programming Language 究竟是该叫 GO 仍是 GOLANG?Google 搜 Why Go is called Golang
能搜到几篇经典帖子。程序员
Rob Pike 在 Twitter 上特地说明是 Go,能够看这个 The language is called Go:github
Neither. The language is called Go, not Golang. http://golang.org is just the the web site address, not the name of the language.
在另一个地方也说明了是 Go,能够看这个 The name of our language is go:golang
The name of our language is Go Ruby is called Ruby, not Rubylang. Python is called Python, not Pythonlang. C is called C, not Clang. No. Wait. That was a bad example. Go is called Go, not Golang. Yes, yes, I know all about the searching and meta tags. Sure, whatever, but that doesn't change the fact that the name of the language is Go. Thank you for your consideration.
这里举了各类例子说明为什么不加 lang 的后缀,固然有个典型的语言是加的,就是 Erlang
。因而就有回复说“Erlang Erlang, Let's just call it Er.”web
那么为何大多时候 Go 和 Golang 都很经常使用呢?在 Why is the Go programming language usually called Golang 中说的比较清楚:算法
It’s because “go domain” has been registered by Walt Disney and so Go creators couldn’t use it. So, they have decided to use golang for the domain name. Then the rest came. Also, it’s harder to search things on search engines just using the word Go. Although, Rob Pike is against this idea but I disagree. Most of the time, for the correct results you need to search for golang. It’s just Go, not golang but it sticked to it.
讲个笑话先,用百度搜下为什么 Go 叫作 Golang,一大片都是相似本文的鸡汤煲,告诉你为什么 Go 才是天地间最合适你的语言,固然本文要成为鸡汤煲中的战斗煲,告诉你全家都应该选择 Go 语言。docker
为什么 Go 语言名字是 Go,可是常常说成是 Golang 呢?有如下理由:后端
为何在名字上要这么纠结呢?嗯嗯,不纠结,让咱们开始干鸡汤吧。api
考虑一个商用的快速发展的业务后端服务器,最重要的是什么?固然是稳定性了,若是崩溃可能会形成用户服务中断,崩溃的问题在 C/C++ 服务器中几乎是必然的:
想象一个 C 服务器,通常不会重头码全部的代码,会从一个开源版本开始,或者从一些网络和线程库开始,而后不断改进和完善。因为业务前期并不复杂,上线也没有发现问题,这时候能够说 C 服务器是稳定的吗?固然不是,只是 Bug 没有触发而已,全部崩溃的 Bug 几乎都不是本次发布致使的。野指针和越界是 C 服务器中最难搞定的狼人,这些狼人还喜欢玩潜伏。
通常业务会日新月异,特别是越偏上层的业务,须要后端处理的逻辑就越多,至于 UTest 和测试通常只存在于传说中,随着业务的发展,潜伏的狼人愈来愈多,甚至开源的库和服务器中的狼人也开始出来做妖。夜路走多了,总会碰到鬼,碰到鬼了怎么办?固然是遇鬼杀鬼了,还能被它吓尿不成,因此就反思解决 Bug,费了老劲、又白了几根头发,终于迎来短暂安宁,而后继续写 Bug。
空指针问题相对很容易查,除零之类的典型错误也容易处理。最完善的解决办法,就是实现 GC,让指针老是有效,无效后再释放,越界时能检测到,这样容易解决问题;其实 Go 早期的版本就和这个很相似了,要实现带 GC 的 C 的同窗,能够参考下 Go 的实现。
如何能直接获取线上的 Profile 数据,须要程序自己支持。好比提供 HTTP API 能获取到 Profile 数据,关键是如何采集这些数据。
Go 的使命愿景和价值观:
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.Go is a concurrent open source programming language developed at Google. Combines native compilation and static types with a lightweight dynamic feel. Fast, fun, and productive.>
Go is an attempt to make programmers more productive. The first goal is to make a better language to meet the challenges of scalable concurrency. The larger goal is to make a better environment to meet the challenges of scalable software development, software worked on and used by many people, with limited coordination between them, and maintained for years.
Go 语言的关键字:
参考 The Path to Go1: What is Go? 和 Another Go at Language Design。
参考 > Go: a simple programming environment。
Go 是面向软件工程的语言,Go 在工程上的思考能够读 Go at Google: Language Design in the Service of Software Engineering 和 Less is exponentially more。Go 最初是解决 Google 遇到的大规模系统和计算的问题,这些问题现在被称为云计算,参考 Go, Open Source, Community。
GITHUT上显示 Go 的项目和 PR 一直在上升,以下图所示。
2014 云计算行业中使用 Go 的有:Docker, Kubernetes, Packer, Serf, InfluxDB, Cloud Foundry’s gorouter and CLI, CoreOS’s etcd and fleet, Vitess | YouTube’s tooling for MySQL scaling, Canonical’s Juju (rewritten in Go), Mozilla’s Heka, A Go interface to OpenStack Swift, Heroku’s Force.com and hk CLIs, Apcera’s NATS and gnatsd。
2018 年全球使用 Go 的公司数目有:US(329), Japan(79), Brazil(52), India(49), Indonesia(45), China(32), UK(32), Germany(28), Israel(24), France(17), Netherlands(16), Canada (15), Thailand(14), Turkey(14), Spain(12), Poland(11), Australia(9), Russia(9), Iran(8), Sweden(7), Korea(South)(6), Switzerland(6), Ukraine(5)。
参考 Go as the emerging language of cloud infrastructure、 The RedMonk Programming Language Rankings: June 2018,还有 GoUsers 以及 Success Stories。
参考 > "Go: 90% Perfect, 100% of the time" -bradfitz, 2014。参考 > Nine years of Go: Go Contributors,社区贡献的代码比例。
咱们一块儿看看这些 Go 牛逼的特性,详细分析每一个点,虽然不能涵盖全部的点,对于经常使用的 Go 的特性咱们作一次探讨和分析。
接下来看一下有关 Go 的重要事件:
sort.Slice
使排序使用更简单;for
支持三种迭代写法;Data Race Detector
等;本文做者:杨成立(忘篱)
本文为阿里云内容,未经容许不得转载。