Reviewer · Naming Conventions
Semantic, consistent naming
Choose identifiers (types, fields, functions, methods, variables, import aliases) that precisely describe what they represent and that match existing naming patterns elsewhere in the codebase, so readers don't have to guess or get misled.
Choose identifiers (types, fields, functions, methods, variables, import aliases) that precisely describe what they represent and that match existing naming patterns elsewhere in the codebase, so readers don’t have to guess or get misled.
Guidelines to apply:
- Name for accuracy over brevity: if a field or function only partially represents what its generic name implies, rename it to reflect the actual semantics. E.g. a field collecting only locally-present content should be
AllPresentContent, notAllContent. - Avoid collisions with similarly-named but semantically different concepts already in the codebase. E.g. prefer
IsNonRootClientoverIsRootlessClientto avoid confusion with an existingIsRootless(daemon rootless mode) check. Similarly, prefer domain-specific terms likeSourceID/TargetIDoverContainerID/HostIDwhen the existing OCI terms would be reversed/misleading in this context. - Keep exported vs. unexported naming consistent with scope: if a type/field/function is only used internally, don’t export it—give it a lowercase, concise name (e.g.
contentinstead ofAllPresentContentwhen it’s package-internal). - Match naming conventions already established by generated code or sibling packages for consistency (e.g. name a constructor
NewClientbecause that’s the convention used inwire.gen.gofor other extension points), and keep import aliases consistent with the rest of the codebase—only alias a package when necessary to avoid a conflict; otherwise use the default name. - Avoid shadowing an outer variable name when refactoring loops or closures; pick a distinct, semantically meaningful name (e.g. use
ofor each item instead of reusingv, which already denotes a different value in the same scope).
Example:
// Avoid: ambiguous/misleading, and shadows outer variable
for _, v := range slices.Backward(rc.options) {
k, v, _ := strings.Cut(v, ":") // shadows outer v
}
// Prefer: clear naming for each loop variable
for _, o := range slices.Backward(rc.options) {
k, v, _ := strings.Cut(o, ":")
}
Before merging, check that each new or renamed identifier: (1) accurately reflects behavior/scope, (2) doesn’t collide in meaning with an existing identifier, and (3) follows the naming/aliasing conventions already used in related code.</description>