Review Go 1.22 & 1.23 new features

Stefanie Lai
8 min readDec 3, 2024
from Unsplash

For years, I have been sticking to reviewing the new features before upgrading the Go version so that I can anticipate the changes and the possible issues I may encounter. It is a good move especially when Go releases a new version almost every six months while some dependent packages stay non-updated.

So far in 2024, Go released 1.22 in February and 1.23 in August, the updates and changes in which are the main focus of this article. I hope you can have a grasp of the important points in these two latest versions even if you stay with Go 1.21.

New Language Features

Non-shared loop variables (1.22)

In versions earlier than Go1.22, the variables declared in the for loop were created only once and updated in each iteration, which would result in the accessing of the value of same address when accessing the value during the traversal. Not being careful with goroutines and loop variables, one of the well-known Go 100 mistakes, is now solved in 1.22.

func main() {
group := sync.WaitGroup{}
list := []int{1,2,3}
for i, j:= range list {
group.Add(1)
go func() {
defer group.Done()
fmt.Println(i, j)// the same address
}()
}
group.Wait()
}
// Before 1.22
2 3
2 3
2 3
2 3

--

--

Stefanie Lai
Stefanie Lai

Responses (2)