-
Use slices instead of arrays, unless the number of elements never changes.
-
Prefer
nilslices 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
appendthe slice.appendadds 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.