Skip to content

Commit

Permalink
style: Document recent Go-pointer exceptions
Browse files Browse the repository at this point in the history
The general rule seems to be:

  If Go's default value has the same semantics we'd use for an unset
  value, don't bother with a pointer.

I'm not sure how well that squares with [1]:

  We want a consistent way to identify unset settings.

But if the falsy values count as "unset", maybe the "null is a
consistent identifier for unset" approach was never really viable.

I'm also not sure if the new style extends to integers where zero has
the same semantics as unset values.  It sounds like Michael was ok
with no pointers for those values [2], but OOMScoreAdj (where zero
clearly means "do nothing") got a pointer in #233 [3].  More clarity
on the threshold would be nice.

[1]: #233 (comment)
[2]: #233 (comment)
[3]: https://github.com/opencontainers/specs/pull/233/files#diff-34c30be66233f08b447fb608ea0e66bbR206

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Jan 26, 2016
1 parent a7b5092 commit 60b83df
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions style.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ The redundancy reduction from removing the namespacing prefix is not useful enou
## Optional settings should have pointer Go types

So we have a consistent way to identify unset values ([source][optional-pointer]).
The exceptions are slices, maps, and booleans where the default should be false, in which case `omitempty` is sufficient and no pointer is needed ([source][no-pointer-for-slices] and [source][no-pointer-for-boolean]).

[capabilities]: config-linux.md#capabilities
[class-id]: runtime-config-linux.md#network
[integer-over-hex]: https://github.com/opencontainers/specs/pull/267#discussion_r48360013
[keep-prefix]: https://github.com/opencontainers/specs/pull/159#issuecomment-138728337
[no-pointer-for-boolean]: https://github.com/opencontainers/specs/pull/290#discussion_r50296396
[no-pointer-for-slices]: https://github.com/opencontainers/specs/pull/316/files#r50782982
[optional-pointer]: https://github.com/opencontainers/specs/pull/233#discussion_r47829711

0 comments on commit 60b83df

Please sign in to comment.