Reviewer · Code Style
Group related code by purpose
Organize code into clearly separated, accurately labeled groups so related concerns stay together and unrelated ones don't get mixed in the same block. This applies to import statements (standard library, external libraries, and internal project packages each in their own block, separated by blank lines), configuration flag/field declarations (group flags...
Organize code into clearly separated, accurately labeled groups so related concerns stay together and unrelated ones don’t get mixed in the same block. This applies to import statements (standard library, external libraries, and internal project packages each in their own block, separated by blank lines), configuration flag/field declarations (group flags that belong to the same feature under a comment that accurately describes that feature, and start a new block/comment when introducing an unrelated feature instead of appending to an existing group), and any other list of declarations that naturally falls into categories.
When the same literal or expression would otherwise be duplicated across multiple branches of an if/switch, extract it into a single local variable computed once, then reuse it, rather than repeating the construction in every branch:
// Instead of duplicating construction in each branch:
if sharded {
return fmt.Sprintf("%s-%s", base, shard)
}
return base
// Prefer a single computed value:
suffix := ""
if sharded {
suffix = "-" + shard
}
return base + suffix
Keep comments next to a group accurate and up to date — if a block comment describes a specific sub-feature (e.g., “time-based sharding”), don’t add unrelated flags to that block or let the comment become misleading. This improves readability, makes it easier to locate related code, and reduces the chance that future changes are added to the wrong logical group.