One mistake no one has ever made. Right?

https://pvs-studio.com/en/blog/posts/go/1393/

4 points · 2 comments · view on lemmy.world

2 Comments

who@feddit.org · 3 pts · 26d

This is a thinly veiled advertisement.

tl;dr: The length of a slice is not a valid index into that slice.

Of course. Because Go uses zero-based indexing, just like many other languages.

uuj8za@piefed.social · 2 pts · 25d

tl;dr arr[len(arr)] is wrong; arr[len(arr)-1] is right because Go uses zero-based indexes like a bunch of other languages.