Organization Overview
Chapters 1 through 5 are the basics, things that are part of any mainstream
imperative language. Go’s syntax and style sometimes differ from other
languages, but most programmers will pick them up quickly.
- Chapter 1
is a tutorial on the basic constructs of Go
, introduced
through a dozen programs for everyday tasks like
- reading and writing files,
- formatting text,
- creating images, and
- communicating with Internet clients and servers.
- Chatpter 2
describes the structural elements of a Go
program
- declarations,
- variables,
- new types,
- packages and files, and
- scope.
- Chapter 3
discusses
- numbers,
- booleans,
- strings, and
- constants, and
- explains how to process Unicode.
- Chapter 4
describes
- composite types, that is,
- types built up from simpler ones using
- arrays,
- maps,
- structs, and
- slices, Go’s approach to dynamic lists.
- Chapter 5
covers
- functions and
- discusses error handling,
-
panic
and
-
recover
, and
- the
defer
statement.
The remaining chapters focus on topics where Go’s approach is less
conventional:
- methods,
- interfaces,
- concurrency,
- packages,
- testing, and
- reflection.
- Chapters 6 and 7
Go has an unusual approach to object-oriented programming.
- There are no class hierarchies, or indeed any classes;
- complex object behaviors are created from simpler ones by composition,
not inheritance.
- Methods may be associated with any user-defined type, not just
structures,
- and the relationship between concrete types and abstract types
(interfaces) is implicit, so a concrete type may satisfy an interface
that the type’s designer was unaware of.
Methods are covered in Chapter 6.
Interfaces are covered in Chapter 7.
- Chapter 8
presents Go’s approach to concurrency,
- which is based on the idea of communicating sequential processes (CSP),
- embodied by goroutines and channels.
- Chapter 9
explains the more traditional aspects of concurrency based on
shared variables.
- Chapter 10
describes packages, the mechanism for organizing
libraries.
This chapter also shows how to make effective use of the go tool, which
provides for
- compilation,
- testing,
- benchmarking,
- program formatting,
- documentation, and
- many other tasks, all within a single command.
- Chapter 11
deals with testing,
- where Go takes a notably lightweight approach, avoiding abstraction-laden
frameworks in favor of simple libraries and tools.
- The testing libraries provide a foundation atop which more complex
abstractions can be built if necessary.
- Chapter 12
discusses reflection,
- the ability of a program to examine its own representation during
execution.
- Reflection is a powerful tool, though one to be used carefully;
- this chapter explains finding the right balance by showing how it is used
to implement some important Go libraries.
- Chapter 13
explains the gory details of low-level programming that uses
the unsafe package
to step around Go’s type system, and when that is
appropriate.