#golang
1 note
- Jul 19, 2026
Go interfaces are implicit: a type satisfies an interface by having the right methods, no
implementskeyword.- Closest Python equivalent is
typing.Protocol(structural subtyping, checked by mypy), but Go enforces it at compile time, not via a separate type checker. - Sharp edge: a nil concrete pointer wrapped in an interface value is not
nil.var dog *Dog = nil; var s Speaker = doggivess != nilbecause the interface holds(*Dog, nil), a typed pair. Bites hardest when returningerrorinterfaces. - Go proverb: "the bigger the interface, the weaker the abstraction." Keep them to 1-3 methods, define where consumed not where implemented.
- Closest Python equivalent is