翻译:《Effective Go —— Introduction》

103 阅读3分钟

前言

想学英语,这是一个学习英语的手段。

  • 如果有翻译错误的地方,欢迎指正,一起学习。
  • 有哪里翻译的不好的地方也欢迎指正,一起学习。

原文

地址

Go is a new language. Although it borrows ideas from existing languages, it has unusual properties that make effective Go programs different in character from programs written in its relatives. A straightforward translation of a C++ or Java program into Go is unlikely to produce a satisfactory result—Java programs are written in Java, not Go. On the other hand, thinking about the problem from a Go perspective could produce a successful but quite different program. In other words, to write Go well, it's important to understand its properties and idioms. It's also important to know the established conventions for programming in Go, such as naming, formatting, program construction, and so on, so that programs you write will be easy for other Go programmers to understand.

This document gives tips for writing clear, idiomatic Go code. It augments the language specification, the Tour of Go, and How to Write Go Code, all of which you should read first.

Note added January, 2022: This document was written for Go's release in 2009, and has not been updated significantly since. Although it is a good guide to understand how to use the language itself, thanks to the stability of the language, it says little about the libraries and nothing about significant changes to the Go ecosystem since it was written, such as the build system, testing, modules, and polymorphism. There are no plans to update it, as so much has happened and a large and growing set of documents, blogs, and books do a fine job of describing modern Go usage. Effective Go continues to be useful, but the reader should understand it is far from a complete guide. See issue 28782 for context.

译文

Go是一门新语言。尽管它借鉴了现有语言的方案,它有不寻常的特性使得Go程序在语法上是不同于与它类似语言的编写。直接将C++或Java程序翻译成Go不太可能产生令人满意的结果——Java程序的编写应该用Java,而不是Go。另一方面,在Go的角度思考问题可能产生一个成功的完全不同的程序。换句话说,想写好的Go程序,了解它的特性和语法是必不可少的,例如:命名,格式化,程序结构等等,以便于你写的Go代码更容易被其它Go开发者理解。

这篇文章提供了编写清晰且常用的Go代码。增强了语言规范,language specificationTour of Go,你应该先阅读这样的所有内容。

2022年1月注释:这个文档为2009年Go的发布编写的,至此以后,没有重大的更新。虽然它是一个理解如何使用语言本身的好的指南,由于语言的稳定性,它很少涉及库以及自Go编写以来的重大变化,比如:构建系统,测试,模块和多态性。由于发生了很多事情,并且有大量的文档,博客和书籍很好的描述了现代Go的使用,因此没有更新它的计划。《Effective Go》将继续使用,但是读者应该知道它远远不是一个完整的指南。看issue 28782这个内容。