Why a new language? ● Frustration with existing languages ● Programming had become too difficult ● Many years with a quiet landscape of choices ● To take advantage of networking and multicore
Code organization ● Keep everything in a single workspace ○ src - source files ○ bin - executable commands ● GOPATH environment variable ($HOME/go) ● Workspace contains multiple repositories ● Import path is the package location in the workspace
Package management ● No official tool yet ● Tools ○ dep - The official experiment ○ Godep ○ Govendor ○ Glide ○ many others ● Modules ○ Preliminary support ○ No need for GOPATH anymore ○ Go 1.13 (August 2019)
Pointers ● Everything in Go is passed by value ● No pointer arithmetic ● Pointer is represented by * ● * is also used to “dereference” ● & returns the memory address ● new function
Go concurrency ● Goroutines ○ Function executing concurrently with other functions in the same address space ○ Goroutines are multiplexed onto multiple OS threads ● Channels ○ Typed, synchronized, thread-safe by design ○ Buffered and Unbuffered (default)
What else is different? ● No decorators ● No named or optional arguments ● No iterators ● No generators ● No exceptions ● Part of the C family ● Labels and goto
fibonacci.go package main import "fmt" func fibonacci(c chan int, n int) { a, b := 0, 1 c <- a for i := 0; i < n; i++ { a, b = b, a+b c <- a } close(c) } func main() { c := make(chan int) go fibonacci(c, 10) for i := range c { fmt.Println(i) } }