← Back to context

Comment by jcarrano

5 hours ago

I found, in my rather recent experience with Go, that using anything other than zero for invalid, default or "sentinel" values is a source of potential problems due to the lack of real constructors.

Yes I'd say 0 should always be treated as a None or Invalid value.

The upside of the lack of real constructors is less incidental complexity which every object having a constructor written which then has to be read and maintained.

Another option of course is to write constructors - there's nothing to stop you doing so in go and using those when creating objects (e.g. foo.New() whenever you want one of these things), but it'd be a convention rather than something required.