Review: 'Learning Go'

Review: 'Learning Go'

New: Learning Go is featured as one of my Best Go Books!

Jon Bodner's new Learning Go (O'Reilly 2021) is simply the best single-volume Go book for experienced developers. I don't say that lightly, as there are a ton of Go books out there, including some efforts of my own. But Jon's done an incredible job.

Being boring

"My first choice for a book title was 'Boring Go'," he explains, and while I can see why his editor may have flinched at that suggestion, I completely agree with him. The Go language is boring, in the sense that there's not much to know about it. Fancy features that excite programming language theorists and CS professors? It doesn't have them.

Inheritance, overloading, pattern-matching, exceptions, immutables? Nah. You name it, Go doesn't have it. (The language has, very grudgingly, and in a limited form, recently acquired generics.)

The nature of Go, therefore, is to be humble, pragmatic, and straightforward, and Jon's aim in this book is to show you how to work in tune with that simplicity, and "build exciting projects with boring code." Bravo.

From zero to Go

The book is aimed squarely at those with some experience of software development in other languages, who simply want a conversion course to Go, and that's fine. You'll be expected to know how to use a command line, text editor, Git, and so forth, and while you don't need a computer science degree (no one does), you'll need to be familiar with programming basics such as variables, types, functions, pointers, concurrency, and so on.

At 374 pages, this is by no means light reading, but it's admirably comprehensive. Jon walks you through essentially everything that's in Go, chapter by chapter, with a generous supply of working code examples. Not satisfied with merely covering the language spec itself, Jon goes on to introduce the most important concepts and packages in the standard library, and more, including unsafe, reflection, and even Cgo, which is niche by anyone's standards. Jon's enthusiasm shines through:

You might be wondering why these advanced concepts appear in a book targeted at those new to Go. There are two reasons. First, developers searching for a solution to a problem sometimes discover (and copy and paste) techniques they don’t fully understand. It’s best to know a bit about advanced techniques that can cause problems before you add them to your codebase. Second, these tools are fun. Because they allow you to do things that aren’t normally possible with Go, it feels a bit exciting to play with them and see what you can do.

What it's not

If I really felt obliged to find some fault with the book, which I don't, it might be that, for my taste, it doesn't put enough emphasis on testing (tests are not introduced until Chapter 13, which makes things a bit awkward for those who are used to test-driven development and want to do it in Go). That said, the coverage of the testing library itself is reasonably comprehensive, if brief, and Jon gives a few examples of non-trivial tests, including stub HTTP handlers and table tests.

Something that almost all Go programmers struggle with, at least at first, is program structure: questions about what packages there should be, what should be in them, how they should import each other, and so on. This is a general difficulty in software engineering, of course, and not specific to Go, so it's no surprise (and no problem) that this book doesn't try to address it.

API design (how should you name your functions, what parameters should they take, what should they return, and many other issues) is something else you won't learn much about here, but that's okay: experience, judgement, and taste will be much more helpful than any prescriptive advice a book could give you anyway. What 'Learning Go' will give you is the confidence to tackle serious Go projects, with a complete knowledge of the language and its idioms, and if you do that, you'll soon be able to teach yourself what good structure and design looks like in Go.

No tears, no fears

What really impressed me about Jon's book is that he is completely unfazed by such traditionally intimidating topics as interfaces, concurrency, contexts, and even generics, explaining each carefully and accurately in plain words. So while this book is eminently suitable for programmers new to Go, it's by no means merely a beginner-level text.

In fact, this book will give you a better, wider, deeper, and certainly more up-to-date knowledge of Go than any other in print. Even highly-experienced Gophers should have this book on their shelves, as an invaluable reference on modern Go.

Introducing Test-Last Development (TLD)

Introducing Test-Last Development (TLD)

Ten commandments of Go

Ten commandments of Go

0