Built-in functions
Go built-ins are language-defined operations, not ordinary library functions; each has narrow operand and result rules.
Canonical guidance
- built-ins are special forms defined by the language
makeandnewsolve different problemsappend,copy,delete,clear,close,len, andcapall have operand-specific rules
Use when
- checking legality of a built-in call
- reasoning about allocation or zeroing
- reviewing slice, map, and channel manipulation
Avoid
- treating built-ins like interchangeable helpers
- using
new([]T)whenmake([]T, n)is intended - assuming
appendorcopyimplies ownership isolation automatically
Preferred pattern
buf := make([]byte, 0, 1024)
buf = append(buf, data...)
Anti-pattern
- using
new(map[string]int)when the code actually needs an initialized map ready for writes
Explanation: This is tempting because both forms allocate something, but new and make produce different kinds of values with different readiness for use.
Why
- built-ins sit on many of Go’s core semantics: allocation, capacity, maps, channels, panics, and copying