Getters
Ordinary Go getters are named after the property, not prefixed with `Get`.
Canonical guidance
- name the getter after the thing being returned
- use
SetXonly when a mutating setter exists and that verb helps clarity - keep accessors boring and obvious
Use when
- naming methods on structs
- reviewing public APIs
- refactoring Java- or C#-influenced code toward idiomatic Go
Avoid
GetName() stringGetHTTPClient()whenHTTPClient()is clear- accessor pairs whose names differ only by habit instead of meaning
Preferred pattern
func (u User) Name() string { return u.name }
Anti-pattern
- carrying
Getprefixes into Go because another language used them
Explanation: This is tempting because accessor conventions transfer from other ecosystems, but in Go the extra verb usually adds noise, not clarity.
Why
- Go call sites read better when ordinary accessors stay short
Related pages
Sources
- Effective Go - Go Team
- Go Code Review Comments - Go Team