Fixing For Loops in Go 1.22 - The Go Programming Language (go.dev)
from spacedogroy@feddit.uk to golang@programming.dev on 19 Sep 2023 21:15
https://feddit.uk/post/2517889

#golang

threaded - newest

lightsecond@programming.dev on 20 Sep 2023 13:55 next collapse

As someone just learning Go, the current behaviour is really unexpected. I’m happy that they are changing it.

bmarinov@lemmy.world on 20 Sep 2023 20:43 collapse

As someone with years of Go experience, this thing bites me or my team in the ass at least once every six months. Sometimes tests catch it, other times the tests get written after the fact and made to fit the implementation. Hilarious bug hunts ensue. I’m happy for this proposal moving forward.

mrkite@programming.dev on 20 Sep 2023 14:38 next collapse

So it’s not really a problem with for loops, it’s a problem with closures inside for loops.

austin@programming.dev on 21 Sep 2023 02:33 collapse

Much needed change, I wish they made it apply for all go versions though