> I disagree. I do that all the time. It's also how `append` was implemented 
> before it existed as a predeclared function. It's also, FWIW, used in 
> bytes.Buffer <https://golang.org/src/bytes/buffer.go#L107>. I agree that 
> unless your API is very clear about it, you shouldn't really access a slice 
> past the length for one of your arguments. But there *are* APIs where it's 
> clear that's happening (e.g. anything having "append" in it's doc-string) 
> and there are use-cases where you control the slice for its entire lifetime 
> and where it can make code more readable.
>

 I didn't even know that append wasn't there, but since we have it isn't it 
meant to be used in the first place?
Of course if we check the capacity, expanding past len is safe, like 
s[:cap(s)]. I would check the capacity only in case when I really don't 
want to end with a new slice buffer as a result of appending more than the 
available space.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/26396fdd-543d-4af0-be95-154d36a505c1%40googlegroups.com.

Reply via email to