Skip to content

Conversation

@matheuscscp
Copy link
Member

Today I saw this message in my IDE:

Screenshot from 2026-01-16 06-01-10

Then I found this:

https://go.dev/doc/go1.22#language

Starting with Go 1.22, for variables are recreated on every iteration, instead of being created only once in the beginning and then updated.

I have used this variable copy+shadowing many times before inside loops and understand why this was needed before Go 1.22, so I'm glad to learn about this improvement.

This language improvement also eliminates the need for this pattern (which also exists in a few places in our codebase):

for i, x := range someSlice {
  go func(i int, x someType) { // these args are no longer needed
    // do something with i and x
  }(i, x)
}

@matheuscscp
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants