Solizardking/clawd-bot / .agents/skills/golang-naming
golang-naming
VerifiedGo (Golang) naming conventions — covers packages, constructors, structs, interfaces, constants, enums, errors, booleans, receivers, getters/setters, functional options, acronyms, test functions, and subtest names. Use this skill when writing new Go code, reviewing or refactoring, choosing between naming alternatives (New vs NewTypeName, isConnected vs connected, ErrNotFound vs NotFoundError, StatusReady vs StatusUnknown at iota 0), debating Go package names (utils/helpers anti-patterns), or asking about Go naming best practices. Also trigger when the user mentions MixedCaps vs snake_case, ALL_CAPS constants, Get-prefix on getters, or error string casing. Do NOT use for general Go implementation questions that don't involve naming decisions.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 12.2 KB |
| evals/evals.json | config | 28.0 KB |
| references/functions-methods.md | markdown | 4.0 KB |
| references/identifiers.md | markdown | 5.1 KB |
| references/packages-files.md | markdown | 3.0 KB |
| references/testing.md | markdown | 1.2 KB |
| references/types-errors.md | markdown | 4.1 KB |
references/identifiers.md
View on GitHub# Variables, Booleans, Receivers & Acronyms
## Variables
Name length SHOULD be **proportional to scope size**. Short names for small scopes, descriptive names for large scopes.
```go
// Small scope (1-7 lines): short names are fine
for i, v := range items {
result = append(result, v.Name)
}
// Medium scope: moderately descriptive
userCount := len(users)
// Large scope / package-level: explicit and clear
var defaultHTTPTransport = &http.Transport{
MaxIdleConns: 100,
}
```
Common single-letter conventions:
| Letter | Meaning |
| ------------- | ---------------------- |
| `i`, `j`, `k` | Loop indices |
| `n` | Count or length |
| `v` | Value (in range loops) |
| `k` | Key (in map ranges) |
| `r` | `io.Reader` |
| `w` | `io.Writer` |
| `b` | `[]byte` or buffer |
| `s` | String |
| `t` | `*testing.T` |
| `ctx` | `context.Context` |
| `err` | Error |
### Avoid Type in the Name
The name should describe what the value represents, not its type.
```go
// Good
users := getUsers()
count := len(items)
// Bad
userSlice := getUsers()
countInt := len(items)
nameString := "hello"
```
### Avoid Repetition with Context
Omit words already clear from the enclosing function, method, or type.
```go
// Good — "user" is clear from the method receiver
func (u *UserService) Create(name string) error { ... }
// Bad — "user" is redundant
func (u *UserService) CreateUser(userName string) error { ... }
```
### Use Predictable Names
The same concept MUST always use the same name across the codebase. If a user is called `user` in one function, it should not become `account`, `person`, or `u` in another. Consistency makes code searchable and reduces cognitive load.
```go
// Good — same concept, same name everywhere
func CreateUser(user *User) error { ... }
func UpdateUser(user *User) error { ... }
func DeleteUser(userID string) error { ... }
// Bad — same concept, different names
func CreateUser(user *User) error { ... }
func UpdateAccount(acct *User) error { ... } // why "acct"? it's a User
func RemovePerson(id string) error { ... } // why "person"? why "remove"?
```
This applies to variables, parameters, functions, and fields. Pick one name per domain concept and stick with it: `order` not sometimes `order` / sometimes `purchase`; `userID` not sometimes `userID` / sometimes `uid` / sometimes `userId`.
### Parameters
Parameters double as documentation at the call site. When the type is descriptive, keep the name short. When the type is ambiguous, use a longer name to clarify intent.
```go
// Good — type is descriptive, short name is fine
func AfterFunc(d Duration, f func()) *Timer
func Escape(w io.Writer, s []byte)
// Good — type is ambiguous (int64, string), longer name documents meaning
func Unix(sec, nsec int64) Time
func HasPrefix(s, prefix string) bool
// Bad — ambiguous type with cryptic name
func Unix(a, b int64) Time // what are a and b?
func HasPrefix(a, b string) bool // which is the prefix?
```
## Booleans
Boolean variables and fields MUST read naturally as true/false questions. Use prefixes like `is`, `has`, `can`, `allow`, `should`. This applies to **both variables and struct fields**.
```go
// Good — struct fields use is/has prefix
type Client struct {
isConnected bool // reads as "client is connected"
hasPermission bool // reads as "client has permission"
}
// Good — variables
isReady := true
hasPermission := user.CanEdit(doc)
// Bad — bare adjective is ambiguous
type Client struct {
connected bool // could be confused with a connection object
permission bool // noun, not a question
}
```
For exported boolean methods, the prefix becomes part of the method name: `IsValid()`, `HasPrefix()`, `CanRetry()`. The unexported field keeps the prefix too: `isConnected` field → `IsConnected()` method.
## Receivers
Receivers MUST be **1-2 letter abbreviations** of the type name. Use the same name across all methods of a type.
```go
// Good — short, consistent
func (s *Server) Start() error { ... }
func (s *Server) Stop() error { ... }
func (s *Server) Handle(r *Request) { ... }
// Bad — too long
func (server *Server) Start() error { ... }
// Bad — inconsistent names across methods
func (s *Server) Start() error { ... }
func (srv *Server) Stop() error { ... }
// Bad — NEVER use "this" or "self"
func (this *Server) Handle(r *Request) { ... }
```
## Acronyms and Initialisms
Acronyms MUST be **all caps or all lower**, NEVER mixed. This preserves readability in MixedCaps names.
```go
// Good
URL // all caps
url // all lower
HTTPServer // HTTP is all caps
xmlParser // xml is all lower
userID // ID is all caps
newHTTPSURL // both HTTPS and URL all caps
// Bad
Url // mixed case acronym
HttpServer // mixed case
userId // mixed case for ID
```
When exporting a lowercase acronym, capitalize the whole thing: `url` → `URL`, `grpc` → `GRPC`, `ios` → `IOS`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |