Jon Jenkins
1 min readFeb 22, 2021

--

I would like to suggest that you're not giving readers a complete picture of how slice allocation works.

`make` is a special function that takes either type and length, or type, length and capacity. I don't think you want your readers to take away that you have to declare the length of every array to avoid using append. The reason the "capacity" parameter exists is so you can pre-declare a slice with allocated capacity if you know it ahead of time, but still have a zero-length slice to append elements to.

Basically, append is there to be used by someone who knows how to use it, it's not meant to be a "less good" shortcut. It should be understood that if you call append on a slice that has a capacity equal to its length, there will be a reallocation.

I suggest brushing up on the excellent "Intro to Slices" article: https://blog.golang.org/slices-intro

--

--

Jon Jenkins

In wine there is truth, in beer there is wisdom, in water there is cholera.