Golang的常见问题中英对照【一】

在Go语言学习的过程中,我们是否有一些关于语言本身的一些疑问?而一些基本问题的答案众说纷纭,没有一个标准。其实,Go语言官方提供了常见问题(Frequently Asked Questions)供开发者参考。

一切问题最权威的回答一定来自官方,该文档从使用者的角度去提问,从设计中的角度去解答,值得我们去阅读和学习。

该文档原文是英文的,为了方便自己和他人学习,笔者在这里把全部内容翻译出来,并使用中英对照的方式分享,希望对有需要的Go开发者有所帮助。

这里是第一部分,回答Go语言起源的一些问题

起源

What is the purpose of the project?

这个项目的目的是什么?

At the time of Go's inception, only a decade ago, the programming world was different from today. Production software was usually written in C++ or Java, GitHub did not exist, most computers were not yet multiprocessors, and other than Visual Studio and Eclipse there were few IDEs or other high-level tools available at all, let alone for free on the Internet.

在 Go 诞生之时,也就是十年前,编程世界与今天不同。生产软件通常是用C++或Java编写的,GitHub不存在,大多数计算机还不是多处理器,除了Visual Studio和Eclipse之外,几乎没有IDE或其他高级工具可用,更不用说在互联网上免费了。

Meanwhile, we had become frustrated by the undue complexity required to use the languages we worked with to develop server software. Computers had become enormously quicker since languages such as C, C++ and Java were first developed but the act of programming had not itself advanced nearly as much. Also, it was clear that multiprocessors were becoming universal but most languages offered little help to program them efficiently and safely.

与此同时,我们对使用我们用于开发服务器软件的语言所需的过度复杂性感到沮丧。自从C,C++和Java等语言首次开发以来,计算机已经变得非常快,但编程行为本身并没有那么进步。此外,很明显,多处理器正在变得普遍,但大多数语言在高效、安全地对它们进行编程方面几乎没有帮助。

We decided to take a step back and think about what major issues were going to dominate software engineering in the years ahead as technology developed, and how a new language might help address them. For instance, the rise of multicore CPUs argued that a language should provide first-class support for some sort of concurrency or parallelism. And to make resource management tractable in a large concurrent program, garbage collection, or at least some sort of safe automatic memory management was required.

我们决定退后一步,思考随着技术的发展,未来几年哪些主要问题将主导软件工程,以及新语言如何帮助解决这些问题。例如,多核CPU的兴起认为,一种语言应该为某种并发性或并行性提供一流的支持。为了使资源管理在大型并发程序中易于处理,需要垃圾回收,或者至少需要某种安全的自动内存管理。

These considerations led to a series of discussions from which Go arose, first as a set of ideas and desiderata, then as a language. An overarching goal was that Go do more to help the working programmer by enabling tooling, automating mundane tasks such as code formatting, and removing obstacles to working on large code bases.

这些考虑导致了一系列讨论,Go从中产生,首先是作为一组思想和desiderata,然后是作为一种语言。一个总体目标是 Go 通过启用工具、自动化代码格式化等日常任务以及消除在大型代码库上工作的障碍来做更多的事情来帮助工作的程序员。

A much more expansive description of the goals of Go and how they are met, or at least approached, is available in the article, Go at Google: Language Design in the Service of Software Engineering.

关于Go的目标以及如何实现或至少接近这些目标的更广泛描述,可以在文章中找到,Go at Google:语言设计在软件工程服务中。

What is the history of the project?

该项目的历史是什么?

Robert Griesemer, Rob Pike and Ken Thompson started sketching the goals for a new language on the white board on September 21, 2007. Within a few days the goals had settled into a plan to do something and a fair idea of what it would be. Design continued part-time in parallel with unrelated work. By January 2008, Ken had started work on a compiler with which to explore ideas; it generated C code as its output. By mid-year the language had become a full-time project and had settled enough to attempt a production compiler. In May 2008, Ian Taylor independently started on a GCC front end for Go using the draft specification. Russ Cox joined in late 2008 and helped move the language and libraries from prototype to reality.

2007 年 9 月 21 日,Robert Griesemer、Rob Pike 和 Ken Thompson 开始在白板上勾勒出一种新语言的目标。几天之内,目标就已经确定为做某事的计划,并对它将是什么有一个公平的想法。设计继续兼职,与不相关的工作并行。到 2008 年 1 月,Ken 开始开发一个用于探索想法的编译器;它生成了 C 代码作为其输出。到年中,该语言已经成为一个全职项目,并且已经足够尝试生产编译器。2008 年 5 月,Ian Taylor 使用规范草案独立地开始了 Go 的 GCC 前端。Russ Cox 于 2008 年底加入,并帮助将语言和库从原型变为现实。

Go became a public open source project on November 10, 2009. Countless people from the community have contributed ideas, discussions, and code.

Go 于 2009 年 11 月 10 日成为公共开源项目。来自社区的无数人贡献了想法、讨论和代码。

There are now millions of Go programmers---gophers---around the world, and there are more every day. Go's success has far exceeded our expectations.

现在全世界有数以百万计的 Go 程序员------gopher,而且每天都在增加。Go 的成功远远超出了我们的预期。

What's the origin of the gopher mascot?

地鼠吉祥物的由来是什么?

The mascot and logo were designed by Renée French, who also designed Glenda, the Plan 9 bunny. A blog post about the gopher explains how it was derived from one she used for a WFMU T-shirt design some years ago. The logo and mascot are covered by the Creative Commons Attribution 4.0 license.

吉祥物和标志由Renée French设计,她还设计了Glenda(Plan 9 bunny)。一篇关于地鼠的博客文章解释了它是如何从她几年前用于WFMU T恤设计的衍生而来的。徽标和吉祥物受知识共享署名 4.0 许可的约束。

The gopher has a model sheet illustrating his characteristics and how to represent them correctly. The model sheet was first shown in a talk by Renée at Gophercon in 2016. He has unique features; he's the Go gopher, not just any old gopher.

地鼠有一张模型表,说明了他的特征以及如何正确表示它们。2016 年,Renée 在 Gophercon 的一次演讲中首次展示了该模型表。他有独特的特征,他是Go地鼠,而不仅仅是任何往常的地鼠。

Is the language called Go or Golang?

这个语言叫做Go还是Golang?

The language is called Go. The "golang" moniker arose because the web site was originally golang.org. (There was no .dev domain then.) Many use the golang name, though, and it is handy as a label. For instance, the Twitter tag for the language is "#golang". The language's name is just plain Go, regardless.

该语言称为 Go。"golang"这个绰号的出现是因为该网站最初是 golang.org 的。(当时没有 .dev 域名。不过,许多人使用golang这个名字,它作为一个标签很方便。例如,该语言的 Twitter 标签是"#golang"。无论如何,该语言的名称只是普通的 Go。

A side note: Although the official logo has two capital letters, the language name is written Go, not GO.

注:虽然官方标志有两个大写字母,但语言名称写的是 Go,而不是 GO。

Why did you create a new language?

为什么你要创造一种新语言?

Go was born out of frustration with existing languages and environments for the work we were doing at Google. Programming had become too difficult and the choice of languages was partly to blame. One had to choose either efficient compilation, efficient execution, or ease of programming; all three were not available in the same mainstream language. Programmers who could were choosing ease over safety and efficiency by moving to dynamically typed languages such as Python and JavaScript rather than C++ or, to a lesser extent, Java.

Go 的诞生源于我们对 Google 现有语言和环境的失望。编程变得太困难了,语言的选择是部分原因。人们必须选择高效编译、高效执行或易于编程;这三者都不是以相同的主流语言提供的。程序员可以通过转向动态类型语言(如Python和JavaScript)而不是C++或在较小程度上选择Java来选择轻松而不是安全和效率。

We were not alone in our concerns. After many years with a pretty quiet landscape for programming languages, Go was among the first of several new languages---Rust, Elixir, Swift, and more---that have made programming language development an active, almost mainstream field again.

我们并不孤单。在编程语言领域经历了多年相当安静的局面之后,Go 是几种新语言(Rust、Elixir、Swift 等)中的第一批语言之一,这些语言使编程语言开发再次成为一个活跃的、几乎是主流的领域。

Go addressed these issues by attempting to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aimed to be modern, with support for networked and multicore computing. Finally, working with Go is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. To meet these goals required addressing a number of linguistic issues: an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on. These cannot be addressed well by libraries or tools; a new language was called for.

Go 通过尝试将解释型动态类型语言的易编程性与静态类型化编译语言的效率和安全性相结合,解决了这些问题。它还旨在实现现代化,支持网络和多核计算。最后,使用 Go 的目的是快速:在一台计算机上构建一个大型可执行文件最多需要几秒钟。为了实现这些目标,需要解决一些语言问题:一个富有表现力但轻量级的字体系统;并发和垃圾回收;刚性依赖规范;等等。库或工具无法很好地解决这些问题;需要一种新的语言。

The article Go at Google discusses the background and motivation behind the design of the Go language, as well as providing more detail about many of the answers presented in this FAQ.

Go at Google 一文讨论了 Go 语言设计背后的背景和动机,并提供了有关本常见问题解答中提出的许多答案的更多详细信息。

What are Go's ancestors?

Go原型是什么?

Go is mostly in the C family (basic syntax), with significant input from the Pascal/Modula/Oberon family (declarations, packages), plus some ideas from languages inspired by Tony Hoare's CSP, such as Newsqueak and Limbo (concurrency). However, it is a new language across the board. In every respect the language was designed by thinking about what programmers do and how to make programming, at least the kind of programming we do, more effective, which means more fun.

Go 主要属于 C 系列(基本语法),有来自 Pascal/Modula/Oberon 系列(声明、包)的大量输入,以及受 Tony Hoare 的 CSP 启发的语言的一些想法,例如 Newsqueak 和 Limbo(并发)。但是,它是一种全面的新语言。在各个方面,这门语言都是通过思考程序员做什么以及如何使编程(至少我们所做的那种编程)更有效,这意味着更多乐趣而设计的。

What are the guiding principles in the design?

设计Go的指导原则是什么?

When Go was designed, Java and C++ were the most commonly used languages for writing servers, at least at Google. We felt that these languages required too much bookkeeping and repetition. Some programmers reacted by moving towards more dynamic, fluid languages like Python, at the cost of efficiency and type safety. We felt it should be possible to have the efficiency, the safety, and the fluidity in a single language.

在设计Go时,Java和C++是编写服务器最常用的语言,至少在Google是这样。我们觉得这些语言需要太多的簿记和重复。一些程序员的反应是转向更动态、更流畅的语言,如 Python,但代价是效率和类型安全。我们认为应该有可能在单一语言中实现效率、安全性和易变性。

Go attempts to reduce the amount of typing in both senses of the word. Throughout its design, we have tried to reduce clutter and complexity. There are no forward declarations and no header files; everything is declared exactly once. Initialization is expressive, automatic, and easy to use. Syntax is clean and light on keywords. Repetition (foo.Foo* myFoo = new(foo.Foo)) is reduced by simple type derivation using the := declare-and-initialize construct. And perhaps most radically, there is no type hierarchy: types just are, they don't have to announce their relationships. These simplifications allow Go to be expressive yet comprehensible without sacrificing, well, sophistication.

Go 试图在这两个意义上减少打字量。在整个设计过程中,我们一直试图减少混乱和复杂性。没有正向声明,也没有头文件;一切都只声明一次。初始化具有表现力、自动性和易用性。语法干净,关键字轻巧。 通过使用 := declare-and-initialize替代( foo.Foo* myFoo = new(foo.Foo) ) 来构造简单的类型派生来减少重复。也许最根本的是,没有类型层次结构:类型就是这样,它们不必声明它们之间的关系。这些简化使 Go 既富有表现力又易于理解,同时又不牺牲复杂性。

Another important principle is to keep the concepts orthogonal. Methods can be implemented for any type; structures represent data while interfaces represent abstraction; and so on. Orthogonality makes it easier to understand what happens when things combine.

另一个重要原则是保持正交概念。方法可以为任何类型实现;结构表示数据,而接口表示抽象;诸如此类。正交性使人们更容易理解当事物结合在一起时会发生什么。

相关推荐
假装我不帅1 小时前
asp.net framework从webform开始创建mvc项目
后端·asp.net·mvc
神仙别闹1 小时前
基于ASP.NET+SQL Server实现简单小说网站(包括PC版本和移动版本)
后端·asp.net
计算机-秋大田2 小时前
基于Spring Boot的船舶监造系统的设计与实现,LW+源码+讲解
java·论文阅读·spring boot·后端·vue
货拉拉技术2 小时前
货拉拉-实时对账系统(算盘平台)
后端
掘金酱2 小时前
✍【瓜分额外奖金】11月金石计划附加挑战赛-活动命题发布
人工智能·后端
代码之光_19803 小时前
保障性住房管理:SpringBoot技术优势分析
java·spring boot·后端
ajsbxi3 小时前
苍穹外卖学习记录
java·笔记·后端·学习·nginx·spring·servlet
架构师那点事儿3 小时前
golang 用unsafe 无所畏惧,但使用不得到会panic
架构·go·掘金技术征文
颜淡慕潇3 小时前
【K8S问题系列 |1 】Kubernetes 中 NodePort 类型的 Service 无法访问【已解决】
后端·云原生·容器·kubernetes·问题解决
尘浮生4 小时前
Java项目实战II基于Spring Boot的光影视频平台(开发文档+数据库+源码)
java·开发语言·数据库·spring boot·后端·maven·intellij-idea