Why Go? ============================================================ A few weeks ago I was asked by a friend, “why should I care about Go”? They knew that I was passionate about Go, but wanted to know why I thought  _other people_  should care. This article contains three salient reasons why I think Go is an important programming language. # Safety As individuals, you and I may be perfectly capable of writing a program in C that neither leaks memory or reuses it unsafely. However, with more than [40 years][5] of experience, it is clear that collectively, programmers working in C are unable to reliably do so  _en masse_ . Despite static code analysis, valgrind, tsan, and `-Werror` being available for a decades, there is scant evidence those tools have achieved widespread acknowledgement, let alone widespread adoption. In aggregate, programmers have shown they simply cannot safely manage their own memory. It’s time to move away from C. Go does not rely on the programmer to manage memory directly, instead all memory allocation is managed by the language runtime, initialized before use, and bounds checked when necessary. It’s certainly not the first mainstream language that offered these safety guarantees, Java (1995) is probably a contender for that crown. The point being, the world has no appetite for unsafe programming languages, thus Go is memory safe by default. # Developer productivity The point at which developer time became more expensive than hardware time was crossed back in the late 1970s. Developer productivity is a sprawling topic but it boils down to this; how much time do you spend doing useful work vs waiting for the compiler or hopelessly lost in a foreign codebase. The joke goes that Go was developed while waiting for a [C++ program to compile][6]. Fast compilation is a key feature of Go and a key recruiting tool to attract new developers. While compilation speed remains a [constant battleground][7], it is fair to say that compilations which take minutes in other languages, take seconds in Go. More fundamental to the question of developer productivity, Go programmers realise that code is  _written to be read_  and so place the [act of reading code above the act of writing it][8]. Go goes so far as to enforce, via tooling and custom, that all code by formatted in a specific style. This removes the friction of learning a project specific language sub-dialect and helps spot mistakes because they just  _look incorrect._ Due to a focus on analysis and mechanical assistance, a growing set of tools that exist to spot common coding errors have been adopted by Go developers in a way that never struck a chord with C programmers—Go developers  _want_  tools to help them keep their code clean. # Concurrency For more than a decade, chip designers have been warning that the [free lunch is over][9]. Hardware parallelism, from the lowliest mobile phone to the most power hungry server, in the form of [more, slower, cpu cores][10], is only available  _if_  your language can utilise them. Therefore, concurrency needs to be built into the software we write to run on today’s hardware. Go takes a step beyond languages that expose the operating system’s multi-process or multi-threading parallelism models by offering a [lightweight concurrency model based on coroutines][11], or goroutines as they are known in Go. Goroutines allows the programmer to eschew convoluted callback styles while the language runtime makes sure that there will be just enough threads to keep your cores active. # The rule of three These were my three reasons for recommending Go to my friend; safety, productivity, and concurrency. Individually, there are languages that cover one, possibly two of these domains, but it is the combination of all three that makes Go an excellent choice for mainstream programmers today. ### Related Posts: 1. [Why Go and Rust are not competitors][1] 2. [Hear me speak about Go performance at OSCON][2] 3. [I’m speaking at GopherChina and GopherCon Singapore][3] 4. [Stress test your Go packages][4] -------------------------------------------------------------------------------- via: https://dave.cheney.net/2017/03/20/why-go 作者:[Dave Cheney][a] 译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 [a]:https://dave.cheney.net/ [1]:https://dave.cheney.net/2015/07/02/why-go-and-rust-are-not-competitors [2]:https://dave.cheney.net/2015/05/31/hear-me-speak-about-go-performance-at-oscon [3]:https://dave.cheney.net/2017/02/09/im-speaking-at-gopherchina-and-gophercon-singapore [4]:https://dave.cheney.net/2013/06/19/stress-test-your-go-packages [5]:https://en.wikipedia.org/wiki/C_(programming_language) [6]:https://commandcenter.blogspot.com.au/2012/06/less-is-exponentially-more.html [7]:https://dave.cheney.net/2016/11/19/go-1-8-toolchain-improvements [8]:https://twitter.com/rob_pike/status/791326139012620288 [9]:http://www.gotw.ca/publications/concurrency-ddj.htm [10]:https://www.technologyreview.com/s/601441/moores-law-is-dead-now-what/ [11]:https://blog.golang.org/concurrency-is-not-parallelism