A change to the implementation of for loops in Go 1.22 avoids accidental sharing bugs. Runtime optimization also is enhanced in update. Credit: Athena Google’s Go (golang) language has reached version 1.22, bringing changes to for loops including a resolution to problem that risked the accidental sharing of loop variables. Released February 6, Go 1.22 can be downloaded and installed from go.dev. Release notes for Go 1.22 can be found on the project website. With Go 1.22, the Go team has resolved what has been called the for loop “gotcha,” leading to accidental sharing of loop variables. In Go 1.22, each iteration of the loop builds new variables to avoid accidental sharing bugs. In a second change, for loops in Go can now range over integers. Also in Go1.22, a runtime optimization improves CPU performance by 1% to 3% while reducing memory overhead of most Go programs by about 1%. Improved devirtualization in profile-guided optimization (PGO) builds also is featured, allowing static dispatch of more interface method calls. Most programs will see improvements of 2% to 14% with PGO enabled. PGO was introduced in Go 1.21, which arrived in August 2022. Go 1.22 also brings improvements to the standard library. A math/rand/v2 package provides a more consistent and cleaner API and uses higher-quality, faster pseudo-random generation algorithms. Also, HTTP routing patterns used by net/http.ServeMux now accept wild cards and methods. Elsewhere in Go 1.22: Go commands in workspaces now can use a vendor directory containing dependencies of the workspace. The trace tool’s web UI has been refreshed as part of the work to support the new tracer, resolving several issues and improving the readability of various sub-pages. The behavior of the vet tool has changed to match the new semantics of loop variables in Go 1.22. Also, vet now reports a non-deferred call to time.Since (t) within a defer statement. On macOS on 64-bit architecture, the Go toolchain now generates position-independent executables by default. Go 1.22 adds an experimental port to OpenBSD on big-endian 64-bit PowerPC. Related content feature What is Rust? Safe, fast, and easy software development Unlike most programming languages, Rust doesn't make you choose between speed, safety, and ease of use. Find out how Rust delivers better code with fewer compromises, and a few downsides to consider before learning Rust. By Serdar Yegulalp Nov 20, 2024 11 mins Rust Programming Languages Software Development how-to Kotlin for Java developers: Classes and coroutines Kotlin was designed to bring more flexibility and flow to programming in the JVM. Here's an in-depth look at how Kotlin makes working with classes and objects easier and introduces coroutines to modernize concurrency. By Matthew Tyson Nov 20, 2024 9 mins Java Kotlin Programming Languages analysis Azure AI Foundry tools for changes in AI applications Microsoft’s launch of Azure AI Foundry at Ignite 2024 signals a welcome shift from chatbots to agents and to using AI for business process automation. By Simon Bisson Nov 20, 2024 7 mins Microsoft Azure Generative AI Development Tools news Microsoft unveils imaging APIs for Windows Copilot Runtime Generative AI-backed APIs will allow developers to build image super resolution, image segmentation, object erase, and OCR capabilities into Windows applications. By Paul Krill Nov 19, 2024 2 mins Generative AI APIs Development Libraries and Frameworks Resources Videos