← GophersCONTENT HISTORYWHAT CHANGED · RULE-BASED ANALYSIS
Update to Gophers
Snapshot Sep 30, 2026 · 23:14 UTC · version 0.1.0
Collection source: not recorded for this historical snapshot.
First saved snapshot
No earlier snapshot is available to establish a change.
Compare saved observations
Download comparison JSONFull technical diff · 0 changed fields
Full snapshot data
{
"description": "Use when naming any Go identifier — packages, types, functions, methods, receivers, variables, constants, errors, options. Covers MixedCaps, scope-based length, initialism casing, the no-`Get` rule, `-er` interfaces, sentinel `ErrX` vs typed `XError`, and the most commonly missed conventions (constructors, boolean fields, enum zero values, lowercase error strings). Apply proactively whenever new identifiers are introduced, even if the user has not asked about naming.",
"included_files": [
{
"relative_path": "agents/openai.yaml",
"size_in_bytes": 209
},
{
"relative_path": "references/functions-and-options.md",
"size_in_bytes": 4741
},
{
"relative_path": "references/identifiers-and-scope.md",
"size_in_bytes": 4089
},
{
"relative_path": "references/types-errors-constants.md",
"size_in_bytes": 4174
}
],
"name": "go-naming",
"skill_md_contents": "---\nname: go-naming\ndescription: \"Use when naming any Go identifier — packages, types, functions, methods, receivers, variables, constants, errors, options. Covers MixedCaps, scope-based length, initialism casing, the no-`Get` rule, `-er` interfaces, sentinel `ErrX` vs typed `XError`, and the most commonly missed conventions (constructors, boolean fields, enum zero values, lowercase error strings). Apply proactively whenever new identifiers are introduced, even if the user has not asked about naming.\"\nlicense: MIT\ncompatibility: \"Designed for Claude Code or similar AI coding agents. Go 1.0+ for the core rules; iota/enum guidance is version-neutral.\"\nallowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*)\n---\n\n# Go Naming Conventions\n\nGo uses naming to encode visibility (`UpperCamelCase` = exported, `lowerCamelCase` = unexported), so naming is load-bearing — not cosmetic. Names should be **short, contextual, and non-repetitive**. The package name is always present at the call site; pretending otherwise is the single biggest source of bad Go names.\n\n## Core Rules\n\n1. **MixedCaps only.** No underscores, no `SCREAMING_SNAKE_CASE`, no `kHungarian`. Exceptions: test subtests (`TestFoo_BadInput`), generated code, cgo.\n2. **Capitalization is visibility.** `Exported`, `unexported`. Do not invent other conventions.\n3. **No stuttering.** The package name is at the call site; `http.HTTPClient` is wrong, `http.Client` is right.\n4. **Scope drives length.** `i` is fine in a 3-line loop; package-level vars need descriptive names.\n5. **Initialisms keep one case.** `userID`, `HTTPServer`, `ParseURL` — never `userId`, `HttpServer`, `ParseUrl`.\n6. **Receivers are 1-2 letter abbreviations**, consistent across all methods of the type. Never `this`/`self`.\n\n## Naming Decision Flow\n\n```\nWhat are you naming?\n├─ Package → lowercase single word, singular, specific (not util/common/helper)\n├─ File → lowercase, underscores OK (user_handler.go)\n├─ Interface → method + \"-er\" when single-method (Reader, Closer, Stringer)\n├─ Struct/Type → MixedCaps noun (Request, FileHeader)\n├─ Constructor → New() if package has one primary type; NewThing() if multiple\n├─ Constant → MixedCaps; never ALL_CAPS; role-based not value-based\n├─ Enum (iota) → type-prefix + Unknown/Invalid at position 0\n├─ Sentinel error → ErrXxx (var ErrNotFound = errors.New(\"...\"))\n├─ Error type → XxxError (type PathError struct{})\n├─ Boolean field → is/has/can prefix (isReady, hasPerm)\n├─ Getter → field name only (Owner()), never GetOwner()\n├─ Setter → SetXxx (SetOwner)\n├─ Option → WithXxx (WithLogger, WithPort)\n├─ Variant → WithContext suffix, In suffix (in-place), Must prefix (panics)\n└─ Variable → length proportional to scope distance\n```\n\n## Quick Reference Table\n\n| Element | Convention | Example |\n|---|---|---|\n| Package | lowercase, singular | `http`, `tabwriter` |\n| Exported | `UpperCamelCase` | `ReadAll`, `HTTPClient` |\n| Unexported | `lowerCamelCase` | `parseToken`, `userCount` |\n| Receiver | 1-2 letters | `func (s *Server)` |\n| Constant | MixedCaps | `MaxRetries`, `defaultTimeout` |\n| Initialism | uniform case | `URL`, `HTTPServer`, `xmlParser` |\n| Sentinel error | `Err` prefix | `ErrNotFound` |\n| Error type | `Error` suffix | `*PathError` |\n| Boolean field | `is`/`has`/`can` | `isConnected` |\n| Option func | `With` + field | `WithPort(8080)` |\n| Format func | `f` suffix | `Errorf`, `Wrapf` |\n\n## Frequently Missed Conventions\n\nThese are correct but non-obvious — they account for most naming mistakes in code review.\n\n### Constructor: `New` vs `NewThing`\n\nIf the package exports **one primary type**, the constructor is `New()`. Callers write `apiclient.New()`, not `apiclient.NewClient()`. Only use `NewThing` when the package builds several things (`http.NewRequest`, `http.NewServeMux`).\n\n### Boolean Fields Get a Prefix\n\nUnexported boolean fields use `is`/`has`/`can`. A bare adjective is ambiguous — is `connected` a method or a field, a state or a verb past tense?\n\n```go\ntype Conn struct { isOpen bool }\nfunc (c *Conn) IsOpen() bool { return c.isOpen }\n```\n\n### Error Strings Are Fully Lowercase\n\nIncluding acronyms. Errors get concatenated: `fmt.Errorf(\"parsing token: %w\", err)` becomes `\"parsing token: invalid message id\"`. Mid-sentence capitals look wrong. Use `\"invalid message id\"` not `\"invalid message ID\"`.\n\nSentinel errors should include the package name: `errors.New(\"apiclient: not found\")`.\n\n### Enum Zero Value Is a Sentinel\n\n`var s Status` is silently `0`. If `0` is `StatusReady`, uninitialised values look intentional. Put `StatusUnknown` (or `Invalid`) at iota 0.\n\n```go\ntype Status int\nconst (\n StatusUnknown Status = iota // zero-value catch\n StatusReady\n StatusRunning\n)\n```\n\n### Subtest Names Are Lowercase Phrases\n\n```go\nt.Run(\"valid id\", ...) // not \"Valid ID\"\nt.Run(\"empty input\", ...)\n```\n\n> Read [references/types-errors-constants.md](references/types-errors-constants.md) when naming new struct/interface/enum/error families.\n\n## MixedCaps Is Load-Bearing\n\n```go\nMaxPacketSize // good\nuserCount // good\nparseHTTPResponse // good\n\nMAX_PACKET_SIZE // wrong — Go reserves casing for visibility\nmax_packet_size // wrong — snake_case\nkMaxBufferSize // wrong — Hungarian\n```\n\n## Avoid Stuttering\n\nThe package name is always present at the call site.\n\n```go\n// In package http\ntype Client struct{} // not HTTPClient — caller writes http.Client\n\n// In package user\nfunc New() *User // not NewUser — caller writes user.New()\n\n// In package dbpool\ntype Pool struct{} // not DBPool\ntype Option func() // not PoolOption\n```\n\n> Read [references/identifiers-and-scope.md](references/identifiers-and-scope.md) for receivers, variable scope rules, and import aliasing.\n\n## Avoid Built-In Names\n\nNever shadow `error`, `string`, `len`, `cap`, `append`, `copy`, `new`, `make`, `nil`, `iota`. The compiler allows it; readers and tools do not.\n\n## Anti-Patterns\n\n| Mistake | Fix |\n|---|---|\n| `MAX_RETRIES = 3` constant | `MaxRetries = 3` — MixedCaps |\n| `GetName() string` getter | `Name() string` — Go omits `Get` |\n| `HttpClient`, `UserId`, `ParseUrl` | `HTTPClient`, `UserID`, `ParseURL` — uniform initialism case |\n| `this`/`self` receiver | One-letter abbreviation (`s` for `Server`) |\n| `util`, `common`, `helpers` package | Specific name that describes content (`stringutil`, `httpauth`) |\n| `user.NewUser()` constructor | `user.New()` — drop the type name |\n| `connected bool` field | `isConnected bool` — prefix reads as a question |\n| `\"invalid message ID\"` error | `\"invalid message id\"` — fully lowercase |\n| `StatusReady` at iota 0 | Add `StatusUnknown` at 0 |\n| `userSlice []User` | `users []User` — types do not belong in names |\n\n## Verification Checklist\n\n- [ ] No identifier contains `_` outside of test subtests, generated code, or cgo.\n- [ ] No `Get` prefix on getters; setters use `Set`.\n- [ ] Initialisms are uniform case (grep `Url\\|Http\\|Json\\|Xml\\|Id\\b` in source).\n- [ ] Receivers across one type all use the same short name.\n- [ ] All sentinel errors are `ErrXxx`; all error types are `*XxxError`.\n- [ ] All iota-based enums place a `Unknown`/`Invalid` value at position 0.\n- [ ] No package named `util`, `common`, `helpers`, `misc`.\n\n## Enforce With Linters\n\nMost rules are mechanical and a linter will catch them in CI:\n\n- `revive` — `var-naming`, `exported`, `receiver-naming`, `error-naming`.\n- `predeclared` — flags identifiers that shadow built-ins.\n- `errname` — enforces `ErrXxx` / `*XxxError`.\n- `misspell` — keeps comments and identifiers consistent.\n\nAdd them to `.golangci.yml` and run `golangci-lint run` in CI.\n\n## References\n\n- [references/identifiers-and-scope.md](references/identifiers-and-scope.md) — receivers, scope-based length, acronyms, import aliasing\n- [references/types-errors-constants.md](references/types-errors-constants.md) — interfaces, structs, enums, sentinel vs typed errors\n- [references/functions-and-options.md](references/functions-and-options.md) — constructors, getters, variants, functional options\n"
}SHA-256 of public snapshot: 88e7e2f8d92e9a2e8304315f8c683cf536948342021d9cb39d69ebd65994f55f