Hackference, 2016
Software Engineer
@JamesLMilner
james@loxodrome.io
Go is a compiled, statically typed programming language created at Google in 2007 by by Robert Griesemer, Rob Pike, and Ken Thompson
# Python
x = 10
x = "Hello World"
x = 1.1
print x
# JavaScript
var x = 10;
x = "Hello World";
x = 1.1;
console.log(x)
function dis() { return this }
// undefined
five = dis.call(5)
// [Number: 4]
five.wtf = 'potato'
// 'potato'
five.wtf
// 'potato'
five * 5 
# 25
five.wtf
// 'potato'
five++ 
// 5
five.wtf
// undefinedpublic class HelloWorld {
    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        String hello = new String("Hello World");
        System.out.println(hello);
    }
}"The problem is you can be productive, or you can be safe, but you can't really be both" - Rob Pike, 2009
and of course...
// JAVASCRIPT (ES5)
var a = "Hello";
var b; // b === undefined
// GO LANG
var string a = "Hello"
var b = "Hello"
c := "Hello"
var d string // Defaults to empty string
// JAVASCRIPT
if (someCondition) {
    doSomething()
} 
else {
    doSomethingElse()    
}// GO LANG
if someCondition {
    doSomething()
} else {
    doSomethingElse()    
}for {
    doSomethingEndlessly()
}
for x < 10 {
    x++
}
for i := 0; i <= 9; i++ {
    fmt.Println(i)
}
for i, num := range nums {
    if num == 3 {
        fmt.Println("index:", i)
    }
}
We do have arrays in Go
We use them far less frequently than slices
Arrays in Go have a fixed length
Slices can be of varying length
Errors are just values in Go
func f1(arg int) (int, error) {
    if arg == 42 {
        return -1, errors.New("can't work with 42")
    }
    return arg + 5, nil
}Errors are just values in Go
package main
	
import "fmt"
func zeroval(ival int) {
    ival = 0
}
func zeroptr(iptr *int) {
    *iptr = 0
}
func main() {
    i := 1
    fmt.Println("initial:", i)
    zeroval(i)
    fmt.Println("zeroval:", i)
    zeroptr(&i) //The &i syntax gives the memory address
    fmt.Println("zeroptr:", i)
}
// PYTHON 2
def vals:
    return [3, 7]
// GO LANG
func vals() (int, int) {
    return 3, 7
}func sum(nums ...int) {
    fmt.Print(nums, " ")
    total := 0
    for _, num := range nums {
        total += num
    }
    fmt.Println(total)
}    
    type Person struct {
        name string
        job string
        age int
        phrase string
    }
    
    hugh := Person{
        name: "Hugh",
        job : "The Spotifys",
        age : 23,
        phrase : "That sound's sub optimal",
    }
    fmt.Println(hugh.phrase)...