notexOPENOverview
Notex/Languages/Code Review: Using Pointers, Slices, and Maps
04.12LESSON 12 OF 20 · 1 MIN READ

Code Review: Using Pointers, Slices, and Maps

Always free to read
  • Prefer value parameters. Use a pointer parameter only when the function must mutate the caller’s value, the type must not be copied, or a struct is genuinely large.

  • If you must optimize performance, always measure before switching to a pointer return value. For small data, returning a value is usually faster.

  • Maps make bad parameters and return values—​not only because they aren’t self-documenting, but because they are always mutable. Prefer a struct unless you don’t know the keys at compile time.

  • Document when a function modifies the contents of a slice argument.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K