translated

This commit is contained in:
geekpi 2017-03-28 10:28:36 +08:00
parent eb7f94c80d
commit fbd49e708d
2 changed files with 63 additions and 64 deletions

View File

@ -1,64 +0,0 @@
translating---geekpi
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. Its 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. Its 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 todays hardware.
Go takes a step beyond languages that expose the operating systems 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. [Im 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

View File

@ -0,0 +1,63 @@
为什么使用 Go 语言?
============================================================
几个星期前,我一个朋友问我:“为什么要关心 Go 语言”? 因为他们知道我热衷于 Go 语言但他们想知道为什么我认为_其他人_也应该关心。本文包含三个我认为 Go 是重要的编程语言的原因。
# 安全
个人而言,你和我或许完全有能力在 C 中编写程序,既不会泄漏内存,也不会不安全地重复使用内存。然而,即使对有超过[ 40 年][5]的经验的人而言,用 C 的程序员也无法可靠地这样做。
尽管静态代码分析、valgrind、tsan 以及 “-Werror” 已经存在了几十年,很少有证据表明这些工具被广泛认可,更不用说广泛采用。总而言之,程序员已经表明他们根本无法自己安全地管理内存。现在是离开 C 的时候了。
Go 不依赖于程序员直接管理内存所有内存分配都由语言运行时管理使用前初始化必要时检查边界。它肯定不是提供这些安全保障的第一个主流语言Java1995可能是该冠军的竞争者。关键是世界对不安全的编程语言没有胃口所以默认情况下Go 是内存安全的。
# 开发人员生产力
在 20 世纪 70 年代末,开发人员时间变得比硬件时间更昂贵这个问题被忽略了。开发人员的生产力是一个广泛的话题,但它归结为这一点:你花了多少时间做有用的工作还是等待编译器或者失望地迷失在外部代码库中。
有个笑话说 Go 是在等待[ C ++ 程序编译][6]时开发的。快速编译是 Go 的一个重要功能,也是吸引新开发人员的关键工具。虽然编译速度仍然是一个[永久的战场][7],但公平地说,在其他语言中需要几分钟的编译,在 Go 中只需要几秒钟。
Go 程序员意识到生产力更根本的问题是代码是为了_读而写的_所以将[代码的阅读行为放在编写之上][8]。Go 通过工具和自定义强制所有代码通过格式化成特定的样式。这消除了学习项目特定语言子方言时的困难并帮助发现错误因为它们_看上去_不正确。
由于专注于分析和机器辅助Go 开发人员开始采用越来越多的工具来发现常见的编码错误,这种工具从来没有在 C 语言中产生共鸣 - Go 开发人员_希望_工具帮助他们保留代码清洁。
# 并发
十多年来,芯片设计师一直在警告[免费午餐将会结束][9]。从最低端的手机到最耗电的服务器,硬件的并行性以[更多、更慢、堆 cpu 内核][10]的形式出现只有_如果_你的语言可以利用它们才能实现。因此并发需要在我们编写的软件中内置到今天的硬件上运行。
通过提供一种基于协程的[轻量级并发模型][11],或者是 Go 中已知的 goroutinesGo 超越了那些暴露操作系统的多进程或多线程并行模型的语言。goroutines 允许程序员避开复杂的回调,而语言运行时确保有足够的线程来保持你的内核的活跃。
# 总结
我给朋友推荐 Go 有三个原因:安全性、生产率和并发性。单独地,有些语言可以涵盖一个也有可能是两个方面,但是这三个方面的结合使得 Go 成为主流程序员的绝佳选择。
###相关文章:
1. [为什么 Go 和 Rust 不是竞争对手][1]
2. [听听我在 OSCON 上谈 Go 语言性能][2]
3. [我在 GopherChina 和 GopherCon Singapore 中的演讲][3]
4. [压力测试你 Go 包][4]
--------------------------------------------------------------------------------
via: https://dave.cheney.net/2017/03/20/why-go
作者:[Dave Cheney][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者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