Francesc Campoy Flores
October 10, 2014

# Things I learned teaching Go

Some thoughts about the difference between learning natural languages and programming languages, false friends, and hard stuff about interfaces.

October 10, 2014

## Transcript

3. ### Making Go easy to learn - live workshops - online

resources - the Go tour - blog posts - documentation - talks

9. ### Java iterating over a collection for (Thing thing: things) Go

iterating over a slice for thing := range things
10. ### Java iterating over a collection for (Thing thing: things) Go

iterating over a slice for thing := range things
11. ### Java iterating over a collection for (Thing thing: things) Go

iterating over a slice for _, thing := range things
12. None

16. ### type Vertex struct { x, y int } func (this

*Vertex) Abs() float64 { x, y := this.GetX(), this.GetY() return math.Sqrt(x*x + y*y) }
17. ### type Vertex struct { x, y int } func (this

*Vertex) Abs() float64 { x, y := this.GetX(), this.GetY() return math.Sqrt(x*x + y*y) }
18. None
19. ### type Vertex struct { _x, _y int } func (self

*Vertex) Abs() float64 { x, y := self._x, self._y return math.Sqrt(x*x + y*y) }
20. ### type Vertex struct { _x, _y int } func (self

*Vertex) Abs() float64 { x, y := self._x, self._y return math.Sqrt(x*x + y*y) }
21. None
22. ### type Vertex struct { x, y int } func (v

*Vertex) Abs() float64 { x, y := v.x, v.y return math.Sqrt(x*x + y*y) }
23. None

26. None

30. ### type Stringer interface { String() string } type myCoolStringer interface

{ String() string }
31. ### type Reader interface { Read([]byte) (int, error) } type Writer

interface { Write([]byte) (int, error) }

39. ### The method set of any other type T consists of

all methods declared with receiver type T. The method set of a pointer type *T is the set of all methods declared with receiver *T or T. The method set of an interface type is its interface
40. ### The method set of any other type T consists of

all methods declared with receiver type T. The method set of a pointer type *T is the set of all methods declared with receiver *T or T. The method set of an interface type is its interface
41. ### The method set of any other type T consists of

all methods declared with receiver type T. The method set of a pointer type *T is the set of all methods declared with receiver *T or T. The method set of an interface type is its interface
42. ### type Person struct { Name string Age int } func

(p *Person) String() string { return fmt.Sprintf("%s is %d", p.Name, p.Age) } func main() { p := &Person{"Hillary", 66} fmt.Println(p) }
43. ### type Person struct { Name string Age int } func

(p *Person) String() string { return fmt.Sprintf("%s is %d", p.Name, p.Age) } func main() { p := &Person{"Hillary", 66} fmt.Println(p) }

45. ### type Person struct { Name string Age int } func

(p Person) String() string { return fmt.Sprintf("%s is %d", p.Name, p.Age) } func main() { p := &Person{"Hillary", 66} fmt.Println(p) }

47. ### The method set of any other type T consists of

all methods declared with receiver type T. The method set of a pointer type *T is the set of all methods declared with receiver *T or T. The method set of an interface type is its interface
48. ### type Person struct { Name string Age int } func

(p Person) String() string { return fmt.Sprintf("%s is %d", p.Name, p.Age) } func main() { p := Person{"Hillary", 66} fmt.Println(p) }

50. ### type Person struct { Name string Age int } func

(p *Person) String() string { return fmt.Sprintf("%s is %d", p.Name, p.Age) } func main() { p := Person{"Hillary", 66} fmt.Println(p) }

→ *T

→ *T *T → T
55. ### func (T) Foo() func (*T) Foo() T → T *T

→ *T *T → T T → *T

57. ### func (T) Foo() func (*T) Foo() T → T *T

→ *T *T → T T ↛ *T

Foo()
59. None

62. ### var p *Person var s fmt.Stringer = p fmt.Println(p, p

== nil) fmt.Println(s, s == nil) # <nil> true # <nil> false

64. ### var p *Person var s fmt.Stringer = p fmt.Printf(“%#v”, s)

# (*main.Person)(nil)

69. ### func do() error { var err *doError … return err

} func main() { if err := do(); err != nil { fmt.Println(err) } }
70. ### func do() error { var err *doError … return err

} func main() { if err := do(); err != nil { fmt.Println(err) } }