Skip to content

Comment on Rust vs. Go: Battle for the Back Endparent

Comments

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...

Issue is that isn’t generated by protoc.

Looking at the go ecosystem you’d think static nil traceability is some sort of Very Hard Problem…

Yep, the ecosystem doesn't support anything like it and a lot of Go people are downright hostile towards this solution :)

You could also try your luck with https://github.com/uber-go/nilaway

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.