go-idiomlisted
Install: claude install-skill CasLubbers/code-design-skills
# Idiomatic Go
## Names scale with scope
The greater the distance between declaration and use, the longer the name. Short names inside short scopes are correct Go, not laziness.
```go
// Good — tight scope, short names
for i, r := range records {
if r.Total > max { max = r.Total }
}
// Good — package-level, long enough to stand alone
const defaultDialTimeout = 30 * time.Second
// Bad — ceremony inside a two-line loop
for recordIndex, currentRecord := range records { ... }
```
Receivers get one or two letters, consistent across every method on the type: `func (s *Server) Start()`, never `func (this *Server)` or `func (server *Server)`.
## No stutter
The package name is part of every identifier a caller reads. Do not repeat it.
```go
// Bad — callers write http.HTTPServer, bytes.BytesBuffer
package http
type HTTPServer struct{}
// Good — callers write http.Server, bytes.Buffer
package http
type Server struct{}
```
Same rule for functions: `user.NewUser()` should be `user.New()`. Package names are short, lowercase, single words, no underscores, no plurals: `store`, not `stores` or `store_utils`.
## Make the zero value useful
A struct should be usable without a constructor wherever possible.
```go
// Good — var buf bytes.Buffer works immediately
var mu sync.Mutex
var buf bytes.Buffer
// Good — zero value is a ready cache
type Cache struct {
mu sync.Mutex
m map[string][]byte // lazily initialised on first write
}
```
Reach for `New…` only when construc