Slice
Arrays are great, but their rigidity around size can cause issues. If you wanted to create a function that accepted an array and sorted the data in it, it could only work for one size of array. That requires you to create a function for each size of array. This strictness around size makes working with arrays feel like a hassle and unengaging. The flip side of arrays is that they are an efficient way of managing sorted collections of data. Wouldn't it be great if there were a way to get the efficiency of arrays but with more flexibility? Go gives you this in the form of slices.
A slice is a thin layer around arrays that let you have a sorted numeric indexed collection without you having to worry about the size. Underneath the thin layer is still a Go array, but Go manages all the details, such as how big an array to use, for you. You use a slice just like you would an array; it only holds values of one type, you can read and write to each element using [
and ]
, and they...