The Go Programming Language is the premier Go book. It is similar
in purpose to The C Programming Language which I consider one of the
few must-read books for any programmer.
The Go Programming Language covers the core language very well, dives
into more advanced language features, gives an overview of how your code
fits into the world with packages and tooling and finally showcases some
rarely used language features.
The core language consists of discussions about types (int
,
runes/characters, etc.), control flow, scopes, arrays, slices, and maps.
Next, I would consider advanced features to be Go’s approach to interfaces
and object-oriented programming along with the chapters about channels and
concurrency. These middle chapters were perhaps the most interesting
with practical advice on how and when to use the language features.
Giving an overview of packages and the go
tooling, it really shows
how you can consume and produce production code. Go 1.11
’s
module system has made some of the text outdated, but some of the advice
is probably under-appreciated at first glance like how to benchmark and
profile code using the Go tools.
Finally, the book does a brief into to reflection and how to interact
with C code. While a bit lighter (and the authors admittedly believe
that these features are not commonly used in most Go code), I have
started appreciating any language’s ability to interact with C code.
Reflection has also been useful when I was programming in
Java, and I imagine whenever you have to write a marshaller/encoder for
a custom format, it will be just as useful.
While someone without programming experience can pick up this book, several of
the concepts such as concurency, closures, and object oriented programming
are only briefly discussed before diving into the application of those
concepts with Go. Several chapters felt like they needed prior
programming experience with a different programming language to appreciate
what the authors were illustrating with their examples and explanations.
A Tour of Go gives most programmers enough to start programming
in Go. However, this book goes further in explaining what is idiomatic
Go code. For example, it gives an explanation on Go’s philiosophy on
error handling, explains why Go does not have a set
type,
and discusses why the testing package is so sparse without assertions
compared to other languages' testing libraries. Whether or not you agree with
the design decisions, having those explanations in mind will lead to more
idiomatic Go code.
My suggestion for anyone looking to pick up Go is to work through
A Tour of Go
, write or port a few simple programs from
another language to Go, and then read The Go Programming Language
.
You may discover several tips (like how to create
internal
packages, why there is a doc.go
file in packages,
why slices
are not comparable, and embedded/anonymous struct fields).
Go does make it “easy to build simple, reliable, and
efficient software”, but there are still conventions,
inconsistencies, and fairly uncommon language features which are
well explained in The Go Programming Language.