Go 1.4 (2014-12-10)
Go 1.4 was released in December 2014, focusing on implementation improvements, including garbage collector optimizations and rewriting the runtime in Go (preparing for Go 1.5 bootstrapping). Additionally, it added official support for Android.
Major Changes
Language
-
For-range Loop: Previously required
for _ = range x, now can be shortened tofor range x.// Before Go 1.4
for _ = range ch { ... }
// Go 1.4 and later
for range ch { ... }
Toolchain
-
Android Support: Go 1.4 can build binaries running on Android ARM processors. With the
golang.org/x/mobilelibrary, you can write Android apps. -
Contiguous Stacks: The runtime now uses contiguous stacks. When stack space is insufficient, a larger new stack is allocated and data is copied, rather than linking a new stack segment as before. This eliminates the "hot stack split" performance issue and allows goroutines to start with a smaller stack (2KB).
-
Canonical Import Paths: Package declarations can include comments to specify their canonical import path. If a user tries to import the package via another path, the
gocommand will refuse to compile.package pdf // import "rsc.io/pdf" -
go generate: Added the
go generatesubcommand, used to scan for//go:generatedirectives in source code and execute corresponding commands. This is typically used for code generation (like Stringer methods, Yacc parsers, etc.). -
Internal Packages: Introduced the concept of
internaldirectories. Packages in a directory namedinternalcan only be imported by code in the directory tree rooted at the parent ofinternal. Although mainly enforced in the main repository in Go 1.4, it laid the foundation for widespread adoption in Go 1.5.
Standard Library
-
testing: SupportsTestMainfunction, allowing global setup and teardown before and after test execution.func TestMain(m *testing.M) {
setup()
code := m.Run()
teardown()
os.Exit(code)
} -
sync/atomic: AddedValuetype for atomically storing and loading values of any type (often used for configuration loading, etc.). -
syscall: Thesyscallpackage is frozen and no new system calls will be added. New system call development has moved to thegolang.org/x/syssub-repository.
References
For more details, please refer to the official release notes: Go 1.4 Release Notes