golang-pitfalls-functions-methods
Installation
SKILL.md
Golang Pitfalls: Functions & Methods
Source material: mistakes #42-47 from 100 Go Mistakes and How to Avoid Them (teivah/100-go-mistakes).
Apply these rules when designing Go functions and methods.
42. Not knowing which receiver to use (#42)
Receiver must be a pointer:
- If the method mutates the receiver (including appending to a slice receiver:
func (s *slice) add(el int)). - If the receiver contains a field that cannot be copied (e.g., a
synctype — see #74).
Receiver should be a pointer:
- If the receiver is a large object (avoids expensive copies; benchmark when unsure).
Receiver must be a value: