Go 1.18, featuring highly anticipated generics capabilities, has moved to a release candidate stage, after two beta releases. However, Go’s developers have postponed the production release of Go 1.18 until March, instead of February, as originally planned.
The release candidate was announced February 17. Installation instructions can be found at go.dev. Prior to the release candidate, a second beta was published January 31 that fixed some obscure bugs in generics, with the goal of ensuring a more stable final release. Generics has been called the most significant change to the programming language since the release of Go 1.0 in 2012.
The Go language server gopls and the Visual Studio Code Go extension now support generics. To install gopls with generics, see this documentation. To configure the VS Code Go extension, follow these instructions.
Go 1.18 Beta 1, which arrived December 14, was the first preview release of the Google-developed open source language containing support for generic code using parameterized types. The first Go 1.18 beta was the most downloaded Go beta ever, with twice as many downloads as any prior beta.
Generic programming is an enhancement enabling representation of functions and data structures in a generic form, with types being factored out. Generics can provide building blocks to share code and make it easier to build programs.
In a blog post marking the initial beta release, the Go team cautioned that with any significant new feature, it was common for users to discover new bugs; generics is not expected to be an exception to this rule. Developers are advised to approach new generics with appropriate caution. Additionally, support for certain subtle cases such as specific kinds of recursive generic types has been postponed to future releases.
Nevertheless, some early adopters have been “quite happy,” the team said. A brief tutorial has been published on getting started with generics. While Go has had interface types, a form of generic programming, it has lacked what Go developers have wanted from generics, according to a July 2019 blog post. For example, advocates for Go generics have sought abilities such as being able to write functions such as
Reverse without caring about the element type of a slice.
Release notes are posted at tip.golang.org. Also in Go 1.18:
- Built-in support is offered for writing fuzzing-based tests, to find inputs that cause a program to crash or return invalid answers. This feature is experimental in Go 1.18.
- A Go workspace mode lets developers work with multiple Go modules simultaneously, which is important for larger projects.
- An expanded
go version -mcommand now records build details such as compiler flags.
- A GOAMD64 environment variable allows users to select any of four versions of the AMD64 architecture.
- The Windows / Arm and Windows / Arm64 ports now support non-cooperative pre-emption, bringing this capability to all four Windows ports and hopefully addressing subtle bugs encountered when calling into Win32 functions that block for extended time periods.
- The garbage collector now includes non-heap sources of GC work when determining how frequently to run. This makes GC overhead more predictable when these sources are significant.
Go 1.17 was released in August. Probably best known for being used in development of the Docker container systemGo was designed to be a simple, easy-to-learn programming language with strong support for concurrency.
Copyright © 2022 IDG Communications, Inc.