Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Stop Using `interface{}` Even in Your Generic Code

DEV Community·Gabriel Anhaia·27 days ago
#Fj5LxtC0
Reading 0:00
15s threshold

Book: Hexagonal Architecture in Go Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub You wrote a generic. You picked a type parameter T . You wrote [T any] because the linter stopped complaining and the function compiled. Then you boxed a value into any halfway down the body to keep a helper "flexible." Then you returned any from a method on a generic struct so callers could "decide later." The signature has square brackets. The body still ferries interface{} around like it's 2021. This is the second wave of any in Go codebases. The first wave was containers and helpers from before generics existed. That one is a known refactor: sweep through, add a type parameter, delete the type assertions. The second wave is more embarrassing because it appears in code that was written after generics shipped. The tool was there.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More