BT

Go 1.9 Introduces Type Aliases, Improves Runtime and Tooling

| by Sergio De Simone Follow 14 Followers on Aug 28, 2017. Estimated reading time: 2 minutes |

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 Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT