BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News New Go 1.4 Adds Support for Android, Improves Garbage Collection

New Go 1.4 Adds Support for Android, Improves Garbage Collection

This item in japanese

Google has announced Go 1.4, coming six months after 1.3. Go 1.4 adds official support for Android native development, albeit still "under heavy development," improved garbage collection, and a minor language change.

As InfoQ reported a few months ago, Google engineers had been working on a proposal to make it possible to write native Android apps in Go. With Go 1.4, Google's draft plan for an experimental port to Android have become a reality, and "it is now possible to write simple Android apps using only Go code," writes Andrew Gerrand, Google engineer on the Go team.

Support is provided through the golang.org/x/mobile repository, which contains packages to generate language bindings that allow calling Go code from Java, to create a fully native app, several examples, as well as bindings for OpenGL.

It must be recalled here that Google's plan did not aim to provide the full Android NDK under Go, rather only to allow writing in Go a subset of Android apps using "a much smaller C-based API surface provided in the Android NDK." From the release notes:

The provided interfaces are focused on games. It is expected that the app will draw to the entire screen (via OpenGL, see the go.mobile/gl package), and that none of the platform's screen management infrastructure is exposed. On Android, this means a native app is equivalent to a single Activity (in particular a NativeActivity) and on iOS, a single UIWindow. Touch events will be accessible via this package. When Android support is out of preview, all APIs supported by the Android NDK will be exposed via a Go package.

Furthermore, as Andrew remarks in the announcement:

"At this stage, the support libraries are still nascent and under heavy development. Early adopters should expect a bumpy ride, but we welcome the community to get involved."

Go 1.4 also includes lot of work to improve the garbage collector and prepare the ground for a fully concurrent collector to be rolled out in the next few releases. Additionally, stacks are now reallocated when necessary to guarantee contiguity and eliminating the notorious "hot stack split" problem.

Tooling has also been improved and the go command now supports build-time source code generation. This can be used to automate the generation of String methods for typed constants using the new stringer tool, says Andrew.

Finally, Go 1.4 adds a couple of changes to the language, namely:

  • new for-range loop form, allowing to write:

    for range x {
    ...
    }
    

    instead of:

    for i := range x {
    ...
    }
    
  • Method calls on **T are forbidden: previous versions of the language allowed the following method call

    type T int
    var x **T
    x.M()
    

    which was not compliant with the Go language specification, which only allows to insert a single dereference automatically. Code dependent on the old behaviour will no longer compile, but is easy to fix by explicitly dereferencing the variable.

For full details, you can read the release notes.

Rate this Article

Adoption
Style

BT