Re:Go Slices Are Fat Pointers
by codedokode on Tuesday July 02, 2019 @09:06AM
(#20334587)
> If you had slices you could easily return a portion of the string without mutation or copy).
In this case you get another problem: how to free memory when there might be many slices pointing at it.
Not that I'm against fat pointers in C, I always thought that in hindsight not having a primitive "slice" type was a mistake. In particular using NUL-terminated strings instead of slices is both error-prone and makes implementing even basic string-splitting functions like strtok annoying or inefficient (you need to be able to mutate the source string to insert the NULs or you have to allocate memory and copy each component. If you had slices you could easily return a portion of the string without mutation or copy).