OpenWest 2014/Go

Ken Thompson - Unix

Google

Gopher - GopherCon 2014

Utah Go Users Group - http://www.utahgophers.com
 * Tues. May 13 @ 6:30pm

The Go Programming Language Specification - The Go Programming Language - http://golang.org/ref/spec

Justifications:
 * C++ too complex
 * compilation too slow
 * programming to difficult
 * easy over safety and efficiency

Issues:
 * Name "Go" is ungoogable / hastagable (use golang) *** MOST ANNOYING ***

Companies who use Go:
 * PayPal
 * Github
 * MongoDB
 * Canonical
 * Mozilla
 * Stack Overflow
 * Puppet Labs

Twitter: #golang Prediction: Will become dominant language for LaaS and PaaS in 24 months

Go is...
 * Compiled
 * Strongly typed
 * Statically typed
 * Garbage collected
 * Similar to C syntax
 * Capable of statically verified duck typing (via interfaces)
 * Open Source

Hello World: package main

import "fmt"

func main { fmt.Println("Hello World") }

Note: Semi colons are optional.

Variables: pakcage main

import "fmt"

func main { var i, j int = 1, 2 k := 3 c, python, java := true, false, "no!" fmt.Println(i, j, k, c, python, java) }

When variables are first initialized, they are always set to their "zero" value. There isn't a null value?

Comments: // comments use C's syntax /* multi line comment */

Functions: package main

import "fmt"

func add(x int, y int) int { return x + y }

func main { fmt.Println(...?? }

Types:
 * bool
 * string
 * int, int32, ...
 * uint, uint8, ...
 * byte
 * rune alias for int32
 * float32
 * complex64

Type conversions - no implicit conversions (have to manually cast)

Looping - Go only has 'for' for i := 0; i < MAX ; i++ { ... }

While: for ; sum < 1000; { sum += sum } for sum < 1000 { sum += sum }

If/Else if x < 0 { ... } else if x > 0 { ... } else { ... }

Don't fear Go pointers type Coordinate struct { X int Y int Z int name string }

func GCP *Coordinate { return &Coordinate{1, 2, 3, "foo"} }

func main { var cp *Coorindate = getCCP fmt.Println(cp) fmt.Printf("%T\n", cp) ... }

Slices

Range var pow = []int{1, 2, 3} func main { for i, v := range pow { fmt.Printf("%d: %d\n", i, v)   } }

for _, v := range pow { ... } // underscore is special

Maps

Access is marked public/private by the first letter of the member. Public is capital. Private is lowercase.

No assertions?

Structs in Go - instead of classes in Object Oriented Programming type House struct { } func (h House) GetHouseName string { } //method defined outside of struct, but works on House

Interfaces are super important in Go. type noiser interface{ GetNoise string } type Cow struct{}  // empty structs type Fox struct{} func (f Fox) GetNoise string { ... }