LeungGeorge / effective-go

只为把Go写得更好

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

简介(Introduction)

Go 是一门新的编程语言。尽管它借鉴了现有语言的**,但其与众不同的特性使得在编写高效的 Go 程序时,与其他语言有着本质的区别。简单的把 C++ 程序或者 Java 程序直接翻译成 Go 程序,不大可能达到令人满意度结果(毕竟 Java 程序是用 Java 写的,不是用 Go)。另一方面,从 Go 的角度去思考问题,可以编写出完全不同但同样可行程序。换句话说,要想把 Go 写好,理解它的特性和风格是很重要的。了解 Go 语言的既定规则也很重要,如:命名,格式化,程序结构等等,这会让你使编写的 Go 程序便于其他程序员理解。

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 代码的技巧。建议先行阅读 language specificationthe Tour of GoHow to Write Go Code

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.

示例(Examples)

Go package sources 旨在不仅作为核心库,也充当着如何使用本语言的示例。此外,一些包包含可运行的、自包含的可执行示例,你可以从网站 golang.org 直接运行。比如 这个(如果需要,点击“Example”展开查看)。如果你有任何问题,诸如:如何解决问题,某些东西是如何实现的疑问,文档、代码以及基础库中的示例可以提供答案、思路、背景知识。

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.

本书使用gitbook编写,采用中英文对照的形式编写。欢迎参与进来,只为写更好的 Go 代码。
gitbook/effective-go
github/effective-go

目录

About

只为把Go写得更好