4 ms·
It's probably not useful in Go's type system. It would be useful if there were union types, though. I sometimes end up using pointers for nullable fields beca
by curryst 6y ago
It's probably not useful in Go's type system. It would be useful if there were union types, though. I sometimes end up using pointers for nullable fields because the zero values are significant in whatever domain I'm working in. I either have to make it a pointer, or I have to implement a new special zero value, or I have to make a struct that can keep track of whether a value has been set or not.
It'd be nice to be able to do
type MyStruct struct {
ID int || nil
}
And have the compiler understand that the ID has to be either an int or nil, and to give me errors if I try to use it as an int without making sure it isn't nil.