Skip to content

Latest commit

 

History

History
17 lines (8 loc) · 3.19 KB

01.Introduction.md

File metadata and controls

17 lines (8 loc) · 3.19 KB

Introduction

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.

Go 是一门全新的语言。尽管它从现有的语言中借鉴了诸多思想,但它拥有许多非同寻常的特性,使得编写高效程序的方式与其它近亲语言有显著的不同。简单粗暴的将C++或者Java的编程思维强加于Go之上的话,结果可能不尽如人意(Java 是 Java, Go 是 Go)。反之,如果站在Go的角度去思考问题,则会柳暗花明,获异曲同工之效。换言之,只有在你了解 Go 的特性,熟悉 Go 的风格之后,你才能用好它。遵循已有的编程惯例和编程规范亦同等重要,诸如命名、格式化、程序结构等等;如此一来,其他的开发者才能更好的理解你编写的程序。

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.

本文档就如何编写清晰的、Go风格化的代码提供了多方面的技巧。请注意,你应该优先阅读 Language SpecificationA Tour of GoHow to write Go code 这些文档,本文是对它们的扩充。

Examples

The Go package sources are intended to serve not only as the core library but also as examples of how to use the language. Moreover, many of the packages contain working, self-contained executable examples you can run directly from the golang.org web site, such as this one (if necessary, click on the word "Example" to open it up). If you have a question about how to approach a problem or how something might be implemented, the documentation, code and examples in the library can provide answers, ideas and background.

Go的源码包不仅仅只作为核心库来提供,它同时也是很好的语言使用范例。而且,很多 package 都包含有效的、自包含的可执行代码示例。你可以直接在golang.org 站点运行它们,比如说 这个例子,你可以点击 Example 来将代码展开(译注:源码文档中的例子都可以就地运行,也可以 copy 到 The Go Playground 去运行)。如果你有任何关于某个问题如何解决或者某种东西如何实现的疑问,你都可以从文档、源码、以及示例中获得答案或者思路。