Know Go: Generics (Go 1.22 edition)

Know Go: Generics (Go 1.22 edition)

$44.95

If you know Go, then you need to know generics. Learn all about type parameters and constraints in Go and how to use them, with this easy-to-read but comprehensive guide to programming with generics in Go. Includes free updates for life.

Reviews

⭐⭐⭐⭐⭐ “Everything I wanted to know about generics in Go, beautifully explained!”
—Pavel Anni

⭐⭐⭐⭐⭐ “It's taken me from being apprehensive about learning something new to being excited about the possibilities that generics brings.”
—Dan Macklin

⭐⭐⭐⭐⭐ “I really loved reading this book. I found the idea of generics scary at first, but now I'm very comfortable with it thanks to John's simple yet complete way of teaching.”
—Shivdas Patil

⭐⭐⭐⭐⭐ “Well written: the explanations and examples are clear and easy to understand.”
—Pedro Sandoval

⭐⭐⭐⭐⭐ “John's writing is personable, human and funny—his examples are realistic and relevant. The test-driven instruction teaches Go in a deep, meaningful and engaging way.”
—Kevin Cunningham

⭐⭐⭐⭐⭐ “Very well written—friendly and informative.”
—Chris Doyle

About the book

If you’re new to Go and generics, and wondering what all the fuss is about, this book is for you! If you have some experience with Go already, but want to learn about the new generics features, this book is also for you. And if you’ve been waiting impatiently for Go to just get generics already so you can use it, don’t worry: this book is for you too!

You don’t need an advanced degree in computer science or tons of programming experience. Know Go: Generics explains what you need to know in plain, ordinary language, with simple examples that will show you what’s new, how the language changes will affect you, and exactly how to use generics in your own programs and packages.

As you’d expect if you enjoyed my previous books, For the Love of Go and The Power of Go: Tools, this is fun and easy reading, but it’s also packed with powerful ideas, concepts, and techniques that you can use in real-world applications.

Table of Contents

What you’ll learn

By reading through this book and completing the exercises, you'll learn:

  • What we mean by generic programming in general, and specifically how that applies to Go

  • What type parameters are, and how they’re different from interfaces

  • How to declare and write generic functions, and when that's necessary (and when it's not)

  • How generics are implemented in Go, and how that affects the way we write programs

  • How to define and use constraints on type parameters, and what constraints are provided in the standard library and the Go language itself

  • How to write type element and type approximation constraints, as well as understanding the changes to interfaces

  • What operations are allowed on generic types, and how to choose the right constraints for them

  • How to define and use generic container types such as slices and maps, and add methods to them

  • How to use the new official cmp, slices, and maps packages, and how standard library APIs are changing

  • Where generics are useful and what new kinds of programs and packages we can write using them

  • What generics can’t do (at least in Go) and when it doesn’t make sense to use them

  • A sneak preview of a new feature that may be coming soon to Go: iterators

And more broadly, you’ll get a great understanding of what the introduction of generics means for Go as a language and ecosystem, how it affects the standard library and third-party libraries, and how we’ll write programs differently as a result.

Read a sample chapter

To help you practise and retain what you’ve learned, there are lots of exercises for you to solve by writing generic code in Go. All the exercises, and solutions, are available on GitHub:

What you get

Your digital download is a ZIP file containing the book in PDF and ePub format. These should be suitable for any ePub reader, computer, phone, or tablet.

Updating to the latest edition

All my books come with free updates for life, so if you’ve bought a previous version of this book, here’s what you need to do to get the latest edition. Click the link in your original download email (make sure you save this, as it’s your key to future updates). You’ll see what looks like an error page saying your download link for the old edition has expired, but that’s okay: click the link in the text, and you’ll be sent a new download email for the current edition.

Add To Cart