Skip to content

Concrete guidance for deciding when Go generics pay off, with constraint and type-alias rules and common pitfalls.

CCM score
65 of 100
skills.sh installs
1.1K
GitHub stars
197
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers when to use generics, decision flow against concrete types and interfaces, type parameter naming, constraint composition, and type aliases
  • Includes bad and good code pairs showing premature generics, unnecessary wrappers, and over-constrained signatures
  • Enforces a rule to start with concrete types and generalize only when a second type appears
  • Designed for Go 1.18+ codebases; cross-references go-interfaces, go-declarations, go-documentation, and go-naming

Install

$ npx -y skills add cxuu/golang-skills --skill go-generics -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Go Generics and Type Parameters

Compatibility: Generics require Go 1.18+.

Resource Routing

  • references/CONSTRAINTS.md - Read when composing constraints, using type sets, or choosing between generics and interfaces.

When to Use Generics

Start with concrete types. Generalize only when a second type appears.

Prefer Generics When

  • Multiple types share identical logic (sorting, filtering, map/reduce)
  • You would otherwise rely on any and excessive type switching
  • You are building a reusable data structure (concurrent-safe set, ordered map)

Avoid Generics When

  • Only one type is being instantiated in practice
  • Interfaces already model the shared behavior cleanly
  • The generic code is harder to read than the type-specific alternative

"Write code, don't design types." — Robert Griesemer and Ian Lance Taylor

Decision Flow

Do multiple types share identical logic?
├─ No  → Use concrete types
├─ Yes → Do they share a useful interface?
│        ├─ Yes → Use an interface
│        └─ No  → Use generics

Bad:

Details

Repository
github.com/cxuu/golang-skills
Category
Go
First seen
Jun 3, 2026

Questions

What does the go-generics skill help with in Go?

The go-generics skill guides you on whether to use Go generics, how to write generic functions and types, and how to choose constraints. It also covers picking between type aliases and type definitions. It applies even when you are writing a utility function that could work with multiple types without mentioning generics.

How do I install the go-generics skill?

Run npx -y skills add cxuu/golang-skills --skill go-generics -y in your project to install it. Once installed, the agent can decide when generics fit your code and avoid premature generics that only ever run with one type.

Which Go category does go-generics belong to, and what sets it apart there?

The go-generics skill sits in the Go category on Claude Marketplaces, where it ranks in the top 100. Its own guidance focuses on generics specifically, including when to avoid them, how to compose constraints with tilde and union operators, and common pitfalls such as over-constraining.

Does go-generics cover interface design?

It does not cover interface design without generics. For that topic, the skill points to go-interfaces, which handles the cases where an interface already models shared behavior cleanly.

What does the go-generics skill need to run?

The skill targets Go 1.18 or later, since generics require that version. The cmp package from Go 1.21 is referenced for standard constraints such as cmp.Ordered, but older versions can still use generics with the constraints package.

More from cxuu/golang-skills

All 20

Similar to Go Generics

More Go