On Jun 26, 2020, at 1:41 PM, Robert Engels <reng...@ix.netcom.com> wrote: > > I don’t think “how it works” is the confusion, more of “how to use it > properly” > > My opinion is that if RTFM is required more than once for a core concept > there may be a design problem. It clearly bites a lot of people. Slices are a > higher level struct, as the underlying array is the same as Java, but Java > doesn’t suffer these knowledge gaps. I’m guessing because it’s higher but not > high enough. Done for performance while forsaking some safety and clarity.
Frankly, I think the problem is with append(). I understand why it's structured the way it is, and yes, I agree the documentation is fairly clear about how it works *if you read it*, but we need to be honest with ourselves about how people read the documentation (or don't). The problem with append() is that it returns a value, and if you only learn by example or quickly skim through the docs (as Howard pointed out), it's not going to be immediately apparently that it's not necessarily a new slice or array. I don't say this because I think append() should be modified to be an in-place operator (that would be impractical and break a lot of things that rely on current behavior) but it shouldn't be mysterious to us that people coming from every language that has a variable-length vector think of it incorrectly because that's how the vast majority of them treat an append operation (either as an in-place or as a copy, and we've kind of split the difference). I wish I had a more constructive answer to this, because I guess you can't make other people's tutorials call this out, and using the return value as a different slice is a valid thing to do even if it is inadvisable without doing more elaborate checking on the capacity, etc, so it's kind of hard to put in a linter. - Dave -- 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/7E5E5A28-4CAE-41DF-A354-320CC7F7ED87%40gmail.com.