BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Go 1.9 Introduces Type Aliases, Improves Runtime and Tooling

Go 1.9 Introduces Type Aliases, Improves Runtime and Tooling

Bookmarks

The biggest change in recently released Go 1.9 is improved support for gradual code repair through the use of type alias declarations. Go 1.9 also improves the garbage collector and the compiler.

Gradual code repair, as explained by Google engineer Russ Cox, is a useful approach to code refactoring, mostly valuable with large codebases. In short, gradual code repair aims to carry through a large refactor in a series of steps, i.e., commits, as opposed to making all the changes atomically, i.e., in one single commit. The atomic refactor approach is usually simpler at a conceptual level, but with large codebases it can produce really big commits, which are hard to review and merge. With gradual code repair, you refactor your code in three steps: first, you introduce the new API, which should be able to coexist with the old API, so you do not need to change all uses of the old API at once; second, you convert all uses of the old API to the new API; finally, you can remove the old API.

To enable gradual code repair, it must be possible to create alternate names for constants, functions, variables, and types. Now, Go allows to define a type alias using a declaration like:

type OldAPI = NewPackage.API

This can be used to make all references to OldAPI automatically use the refactored type. For a broader discussion of gradual code repair, do not miss Russ Cox’s exposition.

As explained by Google engineer Francesc Campoy, most engineering effort for Go 1.9 went into improvements of the runtime, core library, and tooling. The most significant changes are:

  • Go garbage collector provides now better performance thanks to a number of library functions triggering concurrent garbage collection, which only blocks the calling goroutine and not the whole program. Additionally, heap allocation of large objects has been significantly improved.

  • Go 1.9 compiler is now able to compile functions belonging to the same package in parallel. This adds up to parallel compilation of separate packages which was already available in previous versions of the compiler.

  • On the core library front, Go 1.9 makes the use of the time package safe thank to monotonic time tracking. This makes it easier to compare to Time values even in presence of wall clock adjustments. Additionally, the new Map type belonging to the sync package provides a thread-safe concurrent map with constant-time loads, stores, and deletes.

To learn about all the changes that went into Go 1.9, make sure to read the official release notes.

Rate this Article

Adoption
Style

BT