Menu

1 / 2

The Strange Case of Go's nil Interface Comparison

DEV Community·Gabriel Anhaia·6 months ago
#4K8qBNpX
#shape#habit#go#return#type
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

A junior engineer joins your team. Their first PR is a clean

refactor of an error path. The CI passes. Two reviewers approve.

It ships on a Friday afternoon and the on-call rotation gets paged

on Saturday morning because a service that has run fine for two

years suddenly starts panicking under load.

Twelve lines in the diff. One of them is the bug. The fix takes

one keyword: return the untyped nil keyword instead of a typed

pointer through an error interface. If that sentence felt

obvious, this post is not for you. If it did not, sit down,

because this is the bug that bites most Go shops sooner or later

and it is going to bite yours next.

The Comparison That Lies

Run this.…

Continue reading — create a free account

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