AI Snips
Chapters
Transcript
Episode notes
Avoid "new"
- Avoid using the
new
keyword in Go. - Use struct literals for instantiation, as it's consistent and readable, even without setting fields.
Generic Zero Values with "new"
new(T)
is mainly useful in generic Go code.- It helps return the zero value of a generic type T when a direct zero value expression isn't available.
Avoid Full Slice Expressions
- Avoid full slice expressions (with a third index for capacity).
- Their behavior isn't intuitive and may confuse readers; use
slices.clip
for clarity.