Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specs-go: Consistent pointer policy for invalid-value detection? #772

Open
wking opened this issue Apr 15, 2017 · 4 comments
Open

specs-go: Consistent pointer policy for invalid-value detection? #772

wking opened this issue Apr 15, 2017 · 4 comments

Comments

@wking
Copy link
Contributor

wking commented Apr 15, 2017

The nominal original policy for this repository was to use pointers for Go properties that were not always REQUIRED. This was codified in #287, and then reversed in #656 to be anti-pointer. However, in #764, maintainers are again asking for pointers. I think we should have a consistent position on this issue, so here's an attempt to summarize the arguments on each side:

Anti-pointer

Pro-pointer

Consistent policy

While “pointers for every omitempty property is nice and consistent, the consensus position seems to be that the increased complication of pointer handling outweighs the desire for consistency there. That's fine.

We only explicitly support null for some properties inside linux.resources.devices (which I should have removed #656). I haven't heard anyone calling for the ability to distinguish between null and unset in Go, but that's probably orthogonal to the pointer policy because you'd have to use interface{} to do it.

We have to use pointers for optional structs, because of golang/go#11939.

So the contentious point seems to be:

For optional properties where the zero value is invalid (e.g. cpus and, if #764 lands, timeout), do we want to be able to distinguish the cases in Go? Or can Go consumers assume that validation has already been done and treat Go's zero-value cases as “unset”?

We have had maintainers on both sides of that line, and while having an evolving policy is fine, I'd rather not have an inconsistent policy. I'm happy to submit pull requests to unify the repository around whichever position we want to adopt.

@erikh
Copy link

erikh commented Apr 15, 2017 via email

@cyphar
Copy link
Member

cyphar commented Apr 16, 2017

IMO the primary concern should be the semantics of the spec. Does the spec make distinctions between unset fields and fields set to a "default" value (the Go default value is implementation specific but I've noticed that this usually does co-incide) -- and if it does then we need to make that distinction consistent. I've noted that many of these pointer discussions end up with a bunch of flip-flopping over whether the config should make a distinction between empty and "set to zero".

Once we have an agreement on that point implementing it in a way that makes Go's encoding/json happy is a matter of implementation detail. It might end up having to be done with pointers, but we could also implement it by having a default structure that is then unmarshalled into (AFAIK omitempty attributes won't be modified by encoding/json if they aren't present) or by writing wrappers.

@wking
Copy link
Contributor Author

wking commented Apr 19, 2017 via email

@wking
Copy link
Contributor Author

wking commented May 31, 2017

Pointer policy is just about Go, and the Go is non-normative, so this one can get tagged v1.NEXT-maybe. If we don't address it by 1.0, it makes life a bit awkward for folks who'd like to use the 1.0-tagged Go bindings for config compliance testing, but they can always write their own bindings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants