Skip to content

Commit d715acf

Browse files
committed
style: Document recent Go-pointer exceptions
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. Qiang points out that pointers are required to opt-out of boolean settings where both true and false would require action [2], so I've worded the exception to only apply when the Go default for the type is expicitly a no-op in the spec. 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 [3], but OOMScoreAdj (where zero clearly means "do nothing") got a pointer in opencontainers#233 [4]. More clarity on the threshold would be nice; in this commit I've laid out the logic and not explicitly listed the types it applies to. [1]: opencontainers#233 (comment) [2]: https://github.com/opencontainers/specs/pull/317/files#r50932706 [3]: opencontainers#233 (comment) [4]: https://github.com/opencontainers/specs/pull/233/files#diff-34c30be66233f08b447fb608ea0e66bbR206 Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent a7b5092 commit d715acf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

style.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ The redundancy reduction from removing the namespacing prefix is not useful enou
1313
## Optional settings should have pointer Go types
1414

1515
So we have a consistent way to identify unset values ([source][optional-pointer]).
16+
The exceptions are entries where the Go default for the type is a no-op in the spec, in which case `omitempty` is sufficient and no pointer is needed (sources [here][no-pointer-for-slices], [here][no-pointer-for-boolean], and [here][pointer-when-updates-require-changes]).
17+
1618

1719
[capabilities]: config-linux.md#capabilities
1820
[class-id]: runtime-config-linux.md#network
1921
[integer-over-hex]: https://github.com/opencontainers/specs/pull/267#discussion_r48360013
2022
[keep-prefix]: https://github.com/opencontainers/specs/pull/159#issuecomment-138728337
23+
[no-pointer-for-boolean]: https://github.com/opencontainers/specs/pull/290#discussion_r50296396
24+
[no-pointer-for-slices]: https://github.com/opencontainers/specs/pull/316/files#r50782982
2125
[optional-pointer]: https://github.com/opencontainers/specs/pull/233#discussion_r47829711
26+
[pointer-when-updates-require-changes]: https://github.com/opencontainers/specs/pull/317/files#r50932706

0 commit comments

Comments
 (0)