The highly anticipated Go 1.18 programming language has finally been launched as a production release, featuring its groundbreaking generics capabilities. This marks the most significant change to the Go programming language since the initial launch of Go 1.0 in 2012. Go 1.18 can be downloaded at go.dev as of March 15.
Generics has been the most-requested feature by Go programmers, offering support for generic code using parameterized types. Subsequent releases are slated to provide further support for more intricate generic use cases. Users can access information on this feature through a generics tutorial and release notes.
The Go language server, gopls, along with the Visual Studio Code Go extension, now support generics. For instructions on installing gopls with generics, refer to documentation.
The Go 1.18 production release trails its beta and release candidate stages. The initial release had been anticipated for February 2022 but was delayed until mid-March. Go 1.18 Beta 1, which debuted on December 14, was the foremost preview release of the Google-developed open-source language to support generic code using parameterized types. This beta version was also the most downloaded Go beta ever, boasting twice as many downloads as any previous beta release.
Generic programming is an enhancement that allows the representation of functions and data structures in a generic form with types being factored out. This facilitates the sharing of code and simplifies the building of programs.
The Go team advised caution when approaching the new generics capabilities, as new bugs could surface with any significant new feature. Furthermore, support for specific subtle cases, such as certain kinds of recursive generic types, has been deferred to future releases.
Despite this warning, early adopters have reportedly been satisfied with the new feature. A brief tutorial on getting started with generics has been published here. While Go had interface types, a form of generic programming, it lacked certain aspects that Go developers wanted from generics, as reported in a July 2019 blog post. For example, Go generics proponents sought functions like Reverse without concern for the element type of a slice.
The released notes for Go 1.18 also highlight its other key features, such as:
- Built-in support for writing fuzzing-based tests to identify inputs causing a program to crash or return invalid answers. This feature is experimental in Go 1.18.
- A Go workspace mode enabling developers to work with multiple Go modules simultaneously, essential for more extensive projects.
- An enhanced go version -m command that now records build details, such as compiler flags.
- A GOAMD64 environment variable allowing users to choose from four versions of the AMD64 architecture.
- Improvements in CPU performance on Apple M1, ARM64, and PowerPC64 by as much as 20%, attributable to the Go 1.17 register ABI calling convention's expansion to these architectures.
- The Windows/Arm and Windows/Arm64 ports now support non-cooperative pre-emption, making this capability available to all four Windows ports and potentially addressing subtle bugs encountered when calling into Win32 functions that block for extended periods.
- More predictable garbage collection overhead when non-heap sources of GC work are significant, due to the inclusion of these sources when determining the frequency of garbage collection runs.
Go 1.17 was released in August. Go is best known for its use in the development of the Docker container system and was designed to be a simple, easy-to-learn programming language with robust support for concurrency. For developers who wish to explore no-code solutions, such as AppMaster's platform, to create web, mobile, and backend applications, it can help speed up application development and reduce costs while eliminating technical debt.