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

70 阅读6分钟

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

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

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

这是 Golang 的常见问题中英对照的第二篇,官方回答了 Go 使用中的一些问题,我们可以从中了解 Go 语言的应用领域、受欢迎程度、兼容性和开发环境支持等。

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

使用

Is Google using Go internally?

谷歌内部在使用Go吗?

Yes. Go is used widely in production inside Google. One example is Google's download server, dl.google.com, which delivers Chrome binaries and other large installables such as apt-get packages.

是的。Go 在 Google 内部的生产中被广泛使用。一个例子是 Google 的下载服务器(dl.google.com),它提供 Chrome 二进制文件和其他大型可安装文件,例如 apt-get 软件包。

Go is not the only language used at Google, far from it, but it is a key language for a number of areas including site reliability engineering (SRE) and large-scale data processing.

Go 并不是 Google 使用的唯一语言,远非如此,但它是许多领域的关键语言,包括站点可靠性工程 (SRE) 和大规模数据处理。

What other companies use Go?

还有哪些公司使用Go?

Go usage is growing worldwide, especially but by no means exclusively in the cloud computing space. A couple of major cloud infrastructure projects written in Go are Docker and Kubernetes, but there are many more.

Go的使用在全球范围内正在增长,尤其是云计算领域。用Go编写的几个主要云基础设施项目是 Docker 和 Kubernetes ,还有很多。

It's not just cloud, though. The Go Wiki includes a page, updated regularly, that lists some of the many companies using Go.

不过不仅仅限于云领域。Go Wiki 中包括一个定期更新的页面,其中列出了一部分使用 Go 的公司。

The Wiki also has a page with links to success stories about companies and projects that are using the language.

Wiki 中还有一个页面,其中包含有关使用该语言的公司和项目的成功案例的链接。

Do Go programs link with C/C++ programs?

Go 程序可以链接 C/C++ 程序吗

It is possible to use C and Go together in the same address space, but it is not a natural fit and can require special interface software. Also, linking C with Go code gives up the memory safety and stack management properties that Go provides. Sometimes it's absolutely necessary to use C libraries to solve a problem, but doing so always introduces an element of risk not present with pure Go code, so do so with care.

可以在同一个地址空间中同时使用 C 和 Go,但不是天生的契合。可以需要特殊的软件接口。此外,将 C 与 Go 代码链接会丢失 Go 提供的内存安全和堆栈管理属性。有时使用 C 库来解决问题是绝对必要的,但这样做总是会带来纯 Go 代码所没有的风险元素,因此请谨慎行事。

If you do need to use C with Go, how to proceed depends on the Go compiler implementation. There are three Go compiler implementations supported by the Go team. These are gc, the default compiler, gccgo, which uses the GCC back end, and a somewhat less mature gollvm, which uses the LLVM infrastructure.

如果您确实需要将 C 与 Go 一起使用,如何继续则取决于 Go 编译器的实现。Go 团队支持三种 Go 编译器实现。它们是:gc(默认编译器)、gccgo(基于GCC)以及gollvm(一个使用 LLVM 基础结构的不太成熟的编译器)。

Gc uses a different calling convention and linker from C and therefore cannot be called directly from C programs, or vice versa. The cgo program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries.

Gc 使用与 C 不同的调用约定和链接器,因此不能直接从 C 程序调用,反之亦然。cgo 程序提供了“外部函数接口”的机制,允许从 Go 代码安全地调用 C 库。SWIG 将此功能扩展到 C++ 库。

You can also use cgo and SWIG with Gccgo and gollvm. Since they use a traditional API, it's also possible, with great care, to link code from these compilers directly with GCC/LLVM-compiled C or C++ programs. However, doing so safely requires an understanding of the calling conventions for all languages concerned, as well as concern for stack limits when calling C or C++ from Go.

您还可以通过 Gccgo 和 gollvm 使用 cgo 和 SWIG 。由于它们使用传统的API,因此也可以非常小心地将这些编译器中的代码直接与GCC / LLVM编译的C或C++程序链接。但是,安全地这样做需要了解所有相关语言的调用约定,以及从 Go 调用 C 或 C++ 时对堆栈限制的关注。

What IDEs does Go support?

Go支持哪些IDE?

The Go project does not include a custom IDE, but the language and libraries have been designed to make it easy to analyze source code. As a consequence, most well-known editors and IDEs support Go well, either directly or through a plugin.

Go 项目不包含自定义 IDE,但语言和库的设计使其易于分析源代码。因此,大多数知名的编辑器和 IDE 都支持 Go well,无论是直接还是通过插件。

The list of well-known IDEs and editors that have good Go support available includes Emacs, Vim, VSCode, Atom, Eclipse, Sublime, IntelliJ (through a custom variant called Goland), and many more. Chances are your favorite environment is a productive one for programming in Go.

具有良好 Go 支持的知名 IDE 和编辑器列表包括 Emacs、Vim、VSCode、Atom、Eclipse、Sublime、IntelliJ(通过一个名为 Goland 的自定义变体)等等。很有可能你最喜欢的环境是一个高效的 Go 编程环境。

Does Go support Google's protocol buffers?

Go 是否支持 Google 的协议缓冲区?

A separate open source project provides the necessary compiler plugin and library. It is available at github.com/golang/protobuf/.

一个单独的开源项目提供了必要的编译器插件和库。提供在:github.com/golang/protobuf/。

Can I translate the Go home page into another language?

我可以将 Go 主页翻译成其他语言吗?

Absolutely. We encourage developers to make Go Language sites in their own languages. However, if you choose to add the Google logo or branding to your site (it does not appear on golang.org), you will need to abide by the guidelines at www.google.com/permissions…

当然可以。我们鼓励开发人员用他们自己的语言制作 Go 语言网站。但是,如果您选择将 Google 徽标或品牌添加到您的网站(它不会出现在 golang.org 上),则需要遵守 www.google.com/permissions…