Menu

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

Go's Embedding Isn't Inheritance. Stop Treating It Like It Is

DEV Community·Gabriel Anhaia·28 days ago
#5B5rrEVj
#trap#go#oop#architecture#type#method
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming 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've seen it. A Go service ships with a BaseRepository embedded in twenty other repositories, a BaseService embedded in fifteen others, and a Logger embedded into anything that wants a Log method. The team calls it "the base class". They override methods on it, expect virtual dispatch, expect super , and assume interface satisfaction will follow intent. None of those things exist in Go. The shape that looks like inheritance is composition with a side door, and that side door is the source of three bug patterns I keep finding in codebases written by engineers who came across from Java or C#. The Go spec is unambiguous on this. The relevant lines are in Struct types and Selectors .…

Continue reading — create a free account

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

Read More