3 ms·
The problem with nil in Go is that there's no ergonomic way to deal with it. Neither the language nor the type system are amenable to anything better. The lack
by kbolino 2y ago
The problem with nil in Go is that there's no ergonomic way to deal with it. Neither the language nor the type system are amenable to anything better. The lack of the ternary operator or any other conditional value expressions means that handling nil properly always adds at least three lines of code for every dot in an expression. Even generics don't help much because "nil" is actually 5 different things (nil pointer, nil slice, nil map, nil channel, nil interface) none of which are interchangeable. And strings can't be nil, which probably seemed like a cool idea at first but now just means you see *string all over APIs even though string is a fat pointer under the hood.