make(T, ...) — allocates and initializes slices, maps, and channels, returning a usable value. new(T) — allocates zeroed memory for any type, returns a *T pointer.
For slices, make([]int, 0, 100) creates a slice with preallocated capacity. For maps, it creates the hash table. For channels, it allocates the ring buffer. The result is always ready to use.
1buf := make([]byte, 0, 4096) // preallocated buffer2users := make(map[string]*User, 1000) // capacity hint3jobs := make(chan Job, 10) // buffered channel
new returns a pointer to a zeroed value. For simple types this is fine, but for slices/maps/channels the zero value is nil — they need make before use.
1flag := new(bool) // *bool → false, usable2s := new([]int) // *[]int → nil, NOT usable3*s = make([]int, 0) // must call make
When to use:
&T{...} literal syntax for structs.Common mistakes:
new([]int) returns nil slice — must make to use.make([]int, 10) has len=10 (filled with zeros), not an empty slice.make on non-slice/map/channel — compile error.