What is the difference between new and make in Go?
Assesses fundamental understanding of Go conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
new(T) allocates zeroed memory for a value of type T and returns a pointer *T. It works for any type and is rarely used.
make only works for slices, maps and channels. It returns an initialised value of that type (not a pointer) and lets you set length and capacity.
p := new(int) // *int, points to 0
s := make([]int, 0, 8) // len 0, cap 8
m := make(map[string]int)
ch := make(chan int, 4)
The distinction exists because slices, maps and channels need runtime initialisation before use. A zeroed map is nil, and writing to a nil map panics. new(map[string]int) returns a pointer to a nil map, which is almost never what you want. In practice people skip new for structs and take the address of a composite literal instead, for example &User{}.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.