導讀:從問題自己出發,不侷限於 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
等;本文做者:楊成立(忘籬)
本文爲阿里雲內容,未經容許不得轉載。