notexOPENOverview
Notex/Languages/Code Review: Slices and Arrays
01.16LESSON 16 OF 33 · 1 MIN READ

Code Review: Slices and Arrays

Always free to read
  • Use slices instead of arrays, unless the number of elements never changes.

  • Prefer nil slices to empty slice literals.

  • If you know how many elements you need in a slice, size it with make.

  • Don’t use make([]T, length) to create a slice and then append the slice. append adds new values to the end of a slice, starting at position length+1.

  • Use slices.Clone (or copy with a sized destination) to duplicate a slice.

  • Be very careful when slicing slices. Treat the resulting slices as read-only to avoid data sharing surprises.

  • Before writing your own slice manipulation function, check the standard library to make sure it hasn’t already been implemented.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

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