News for hackers. Stuff that matters.
Re:a[low:high:max] in Golang – A Rare Slice Trick by Groxx on Saturday March 18, 2023 @10:12PM (#35215304)
cap==len is effectively the default - most slicing is done with [start:end], not [start:end:additional-cap]
Re:a[low:high:max] in Golang – A Rare Slice Trick by iainmerrick on Saturday March 18, 2023 @11:28PM (#35215737)
No it’s not -- I just checked the language specification and it says:

After slicing the array a

a := [5]int{1, 2, 3, 4, 5}

s := a[1:4]

the slice s has type []int, length 3, capacity 4

Many of us here are arguing that the default should be cap==len==3, but it’s not, it’s 4.

Re:a[low:high:max] in Golang – A Rare Slice Trick by Groxx on Monday March 20, 2023 @12:08AM (#35227172)
Welp. TIL.

Yeah, that's much more error prone I think. It's the sort of thing that only kinda makes sense on zero-valued arrays... and even then it's dubious at best.

Bleh. I'm gonna go review some old code now D: