Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Looks as though the range loop isn't an issue from Go 1.22 anymore.

https://go.dev/blog/loopvar-preview



That's a different language design mistake, which several languages have had to fix including C# back in C# 5.

The question there is, does our for-each style loop make a new variable each iteration, with the appropriate value, or does it have a single variable and it's just re-assigned for each iteration. People who haven't designed a language before might think the second option sounds optimal and won't make a practical difference, but it's actually very annoying and that's why Go changed to the former.

This time though it's not about the variable staying the same, the problem is that we got a copy of the data we cared about, not a mutable reference to that data.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: