8.8 nil Slices vs Empty Slices
Right, let’s settle this. You’ve probably seen both nil and empty slices in the wild and maybe even used them interchangeably. That works… until it spectacularly doesn’t. The difference is one of the most beautifully subtle, yet profoundly important, distinctions in Go. It’s the difference between having absolutely nothing (nil), and having something that happens to contain nothing (an empty slice). Think of it this way: a nil slice is like having a blank check. You haven’t committed to any specific bank account (backing array), and the check’s “amount” field (length and capacity) is zero. An empty slice is like writing a check for $0.00 from your very real, but currently empty, checking account. The effect of trying to spend that money is the same (you get nothing), but the underlying financial reality is different.