Go Time: Golang, Software Engineering

The bits of Go we avoid (and why)

13 snips
Mar 16, 2023
A lively tour of Go features the panel tends to leave on the shelf, from full slice expressions, naked returns, panics, and labels to global state, init functions, and internal packages. They debate when explicit code beats clever syntax, share personal coding pet peeves, and detour into robots, password managers, and keeping keyboards clean.
Ask episode
AI Snips
Chapters
Transcript
Episode notes
ADVICE

Avoid "new"

  • Avoid using the new keyword in Go.
  • Use struct literals for instantiation, as it's consistent and readable, even without setting fields.
INSIGHT

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.
ADVICE

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.
Get the Snipd Podcast app to discover more snips from this episode
Get the app