Skip to content

Generics: resources

Level: 201 · anyone who wants the primary sources behind this chapter

One line: The spec sections, release notes, design documents, blog posts, books and talks that settle what this chapter claims about type parameters — and three sources to read with care.

Primary sources

Books

  • Jon Bodner, Learning Go: An Idiomatic Approach to Real-World Go Programming, 2nd ed. (O'Reilly, 2024), chapter 8, "Generics" — "Introducing Generics in Go" (a stack, and the zero value in Pop), "Generic Functions Abstract Algorithms", "Generics and Interfaces", "Use Type Terms to Specify Operators", "Type Inference and Generics", "Type Elements Limit Constants", "Combining Generic Functions with Generic Data Structures", "More on comparable", "Things That Are Left Out", "Idiomatic Go and Generics", "Adding Generics to the Standard Library". The most complete book treatment on the shelf, and current for Go 1.22.
  • Go in Practice, 2nd ed. (Manning, 2025), chapter 3, "Structs, interfaces, and generics" — section 3.4, "Simplifying code with generics", with "Using functions with generics" and "Using constraints and type approximations".
  • Miki Tebeka, Effective Go Recipes: Fast Solutions to Common Tasks (Pragmatic, 2024), chapter 7, "Working with Structs, Methods, and Interfaces" — Recipe 39, "Using Generics to Reduce Code Size"; Recipe 40, "Using Generics for Type-Safe Data Structures"; Recipe 41, "Using Generics for Better Type Safety".

Not on the shelf

  • Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022) — publisher's page ↗; its mistakes on generics are about when not to use them.
  • Bartłomiej Płotka, Efficient Go (O'Reilly, 2022) — the book's example repository ↗; on measuring costs, for readers of the GC-shape document who want to benchmark an instantiation.

Talks and videos

Read with care

  • Alan A. A. Donovan and Brian W. Kernighan, The Go Programming Language (Addison-Wesley, 2015) — written for Go 1.5, seven years before type parameters: its sort.Interface and interface{} idioms are how the same problems were solved without generics, and its chapter 7, "Interfaces", is still the best account of what a basic interface is. Nothing in it is wrong; nothing in it mentions [T any].
  • Adam Freeman, Pro Go (Apress, 2022) — covers Go 1.17 and has no generics at all, so its container and "any value" chapters solve with interface{} what this chapter solves with type parameters.
  • The pre-1.18 design drafts — contracts (2018–2019), and code written against golang.org/x/exp/constraints: constraints.Ordered became cmp.Ordered ↗ in Go 1.21, and the rest of that package (Integer, Float, Signed) never moved into the standard library.
  • Anything that says an interface type cannot be a comparable type argument — true until Go 1.19, false since 1.20 (Constraints are type sets).
  • Anything that says slices.SortFunc(xs, cmp.Compare[string]) needs the explicit instantiation — true until Go 1.20, unnecessary since 1.21 (Inference works from arguments, not results).

Checked 2026-09-23.