3 ms·
append has a good reason for that, it can potentially reallocate the slice and return a new pointer. This is an expression of the underlying truth of the implem
by Sir_Cmpwn 8y ago
append has a good reason for that, it can potentially reallocate the slice and return a new pointer. This is an expression of the underlying truth of the implementation that they chose not to abstract over, a decision I personally appreciate.
- TheCoelacanth 8y agoThat's just a language that is insufficiently powerful to express the underlying truth. In C++ or Rust, the same construct could be expressed without loss of efficiency and without the leaky abstraction.
- Sir_Cmpwn 8y agoCan you elaborate?
- TheCycoONE 8y agoNot the original poster, but in C++ you would be using a container, likely a vector so the internal data could move, but because the container is updated the caller can be unaware. The abstraction leaks a bit. The result of a data() or c_str() call cannot be trusted after the vector is manipulated. When passing a vector by reference to another function you effectively get a double pointer (abstracted behind a reference and a container) so the inner one can be moved. I'm not familiar with go, but if it is like C in this respect append would have been clearer with a double pointer and no return value.