Go Talks From Google I/O 2012

Here are the videos from the Go talks held at Google I/O 2012! Very interesting.

Computing Map Tiles with Go on App Engine

Go In Production

Go Concurrency Patterns

Meet the Go Team

A Tour of Go

Here’s an excellent introduction to the Go programming language by Russ Cox:

Russ’ post has the answers to questions posed at the end of the original talk.

Apollo Program Source Code

The source code and documentation for the Apollo and Gemini computing systems is now publicly available. It’s so fascinating to consider how badly the USSR wanted this back in the day.

I’m happy to see that the engineers had a sense of humor (scroll right for the comments):

034083,000236: 32,3233           05353                          TC       PHASCHNG                              #  PREVENT RECALLING R60
034084,000237: 32,3234           04024                          OCT      04024                                 
034086,000239: 32,3235           34746        P63SPOT3          CA       BIT6                                  #  IS THE LR ANTENNA IN POSITION 1 YET
034087,000240: 32,3236           00006                          EXTEND                                         
034088,000241: 32,3237           02033                          RAND     CHAN33                                
034089,000242: 32,3240           00006                          EXTEND                                         
034090,000243: 32,3241           13247                          BZF      P63SPOT4                              #  BRANCH IF ANTENNA ALREADY IN POSITION 1
034092,000245: 32,3242           33254                          CAF      CODE500                               #  ASTRONAUT:     PLEASE CRANK THE
034093,000246: 32,3243           04616                          TC       BANKCALL                              #                 SILLY THING AROUND
034094,000247: 32,3244           20623                          CADR     GOPERF1                               
034095,000248: 32,3245           16001                          TCF      GOTOP00H                              #  TERMINATE
034096,000249: 32,3246           13235                          TCF      P63SPOT3                              #  PROCEED        SEE IF HE'S LYING
034098,000251: 32,3247           04616        P63SPOT4          TC       BANKCALL                              #  ENTER          INITIALIZE LANDING RADAR
034099,000252: 32,3250           67721                          CADR     SETPOS1                               
034101,000254: 32,3251           04635                          TC       POSTJUMP                              #  OFF TO SEE THE WIZARD ...

Go 1 Has Been Released

Andrew Gerrand writes:

Today marks a major milestone in the development of the Go programming language. We’re announcing Go version 1, or Go 1 for short, which defines a language and a set of core libraries to provide a stable foundation for creating reliable products, projects, and publications. Go 1 is the first release of Go that is available in supported binary distributions. They are available for Linux, FreeBSD, Mac OS X and, we are thrilled to announce, Windows.

The driving motivation for Go 1 is stability for its users. People who write Go 1 programs can be confident that those programs will continue to compile and run without change, in many environments, on a time scale of years. Similarly, authors who write books about Go 1 can be sure that their examples and explanations will be helpful to readers today and into the future.

Forward compatibility is part of stability. Code that compiles in Go 1 should, with few exceptions, continue to compile and run throughout the lifetime of that version, even as we issue updates and bug fixes such as Go version 1.1, 1.2, and so on. The Go 1 compatibility document explains the compatibility guidelines in more detail.

Go 1 is a representation of Go as it is used today, not a major redesign. In its planning, we focused on cleaning up problems and inconsistencies and improving portability. There had long been many changes to Go that we had designed and prototyped but not released because they were backwards-incompatible. Go 1 incorporates these changes, which provide significant improvements to the language and libraries but sometimes introduce incompatibilities for old programs. Fortunately, the go fix tool can automate much of the work needed to bring programs up to the Go 1 standard.

Go 1 introduces changes to the language (such as new types for Unicode characters and errors) and the standard library (such as the new time package and renamings in the strconv package). Also, the package hierarchy has been rearranged to group related items together, such as moving the networking facilities, for instance the rpc package, into subdirectories of net. A complete list of changes is documented in the Go 1 release notes. That document is an essential reference for programmers migrating code from earlier versions of Go.

We also restructured the Go tool suite around the new go command, a program for fetching, building, installing and maintaining Go code. The go command eliminates the need for Makefiles to write Go code because it uses the Go program source itself to derive the build instructions. No more build scripts!

Finally, the release of Go 1 triggers a new release of the Google App Engine SDK. A similar process of revision and stabilization has been applied to the App Engine libraries, providing a base for developers to build programs for App Engine that will run for years.

Go 1 is the result of a major effort by the core Go team and our many contributors from the open source community. We thank everyone who helped make this happen.

There has never been a better time to be a Go programmer. Everything you need to get started is at golang.org.

The Go website has been updated, and binary distributions are now available (and the de facto standard) for the different platforms.

For a small list of the major changes between the last stable release of Go, r60.3, and Go 1, see From r60 to Go 1, or the Go 1 Release Notes for a more comprehensive list.

From r60 to Go 1

Go 1 is right on the doorstep, and, boy, are there a lot of changes!

Here are the big things you need to know about:

The Go command

Go has a new master command, go, which replaces or complements all of the old go commands:

Before Now
godoc go doc
gofix go fix
gofmt -l -w *.go go fmt
goinstall go get
gorun go run
gotest go test
govet go vet
make go build
make clean go clean
make install go install

(Most of the utility commands, including 6g/8g, 6l/8l, 6cov/8cov, gotype, gopprof, and 6prof/8prof are now under go tool <6g/pack/prof/...>. See go tool for a full list.)

Goodbye Makefiles

Go 1 has done away with Makefiles, which were always a temporary solution anyway. Instead, everything—how to get a package, how to compile it, and how to test it—is deduced by looking at the source files, and from a single environment variable, GOPATH.

For Go 1 to be able to build any package, that package must reside in a path listed in GOPATH. (If GOPATH is not set, go uses its own directory.)

  • All compiled binaries are stored in GOPATH/bin
  • All compiled packages are stored in GOPATH/pkg/<arch>/<import path>
  • All source code is stored in GOPATH/src/<import path>

This means that if you have a package github.com/patrickmn/helloworld, the source files should be stored in one of the directories listed in GOPATH under src/github.com/patrickmn/helloworld. When you run go install, the compiled package appears in that same GOPATH folder under pkg/<arch>/github.com/patrickmn/helloworld.

Because of these new conventions, GOPATH is all of the configuration Go needs. No Makefiles, no custom scripts, and no worrying about naming conflicts.

Here’s an example you could use to be able to build and run all of your own projects, while at the same time avoiding cluttering your projects folder with external source code (e.g. from using go get):

In ~/.profile:

export GOPATH=$goroot:$mygo
export PATH=$PATH:$gobin

Because the Go folder is the first path listed in GOPATH, this is the default destination used by commands like go get—but since your projects already reside in the second folder, its bin and pkg folders are used to store your compiled projects.

(If you don’t have write access to the Go folder, you can just specify another folder to use as the default instead of goroot. go get will install all new third-party packages there.)

(When you build a project that imports a package, e.g. github.com/patrickmn/helloworld, Go looks for it in all of the paths listed in GOPATH.)

To understand the thinking behind this, see Russ Cox’s message to the golang-nuts mailing list titled The Go Command.

New map delete syntax

You now use delete(map, "key") instead of map["key"] = nil, false.

Errors have their own package

Errors have moved from os to errors. Also, error is now a built-in type, so you don’t have to import anything to be able to work with it.

Before Now
os.Error error
os.NewError(text string) os.Error errors.New(text string) error
err.String() string err.Error() string

Library reorganization

See this table for a list of old and new package import paths. (All of them are fixed automatically by go fix.)

Rewritten libraries

Package Change
strconv Significantly reworked
template Replaced by text/template which has an entirely new API
time Completely redesigned
url Moved to net/url with several changes, most significantly to url.URL where URL.Raw has been removed and URL.String() should be used instead

New libraries

Package Description
database/sql A standardized interface for interacting with relational databases (drivers exist for SQLite, MySQL, PostgreSQL, and more)
html/template An XSS-safe wrapper for text/template

xdThis is by no means a comprehensive list of the changes introduced to the language and the package library in Go 1. Please see the Go 1 release notes (work in progress) and the weekly snapshot history for more details.