|
|
|
|
|
by Mawr
468 days ago
|
|
Assume all pointers are non-nil and use a generic Option type to represent values that may or may not exist: type Option[Value any] struct {
value Value
exists bool
}
func (o Option[Value]) Get() (Value, bool) {
return o.value, o.exists
}
So long as all such values use this type instead of abusing the nullability of pointers, you'll eliminate the problem of programmers forgetting to check for nil.It's not without its issues though, the ecosystem does not use such a type and you need a little bit of discipline to stick with it. But it's not that big of a deal if you're getting regular major outages... |
|
Looking at the go ecosystem you’d think static nil traceability is some sort of Very Hard Problem…