_content/talks/2010/go_talk-20100112.html
package main
import "fmt"
func main() {
fmt.Printf("Hello, 世界\n")
}
var one, hi = 1, "hello"
var double = func(x int) int { return x*2 }
type Point struct {
X, Y float64
}
func (p Point) Abs() float64 {
return math.Sqrt(p.X*p.X + p.Y*p.Y)
}
type MyFloat float64
func (f MyFloat) Abs() float64 {
v := float64(f)
if v < 0 {
v = -v
}
return v
}
type Abser interface {
Abs() float64
}
func AbsPrinter(a Abser)
p := Point{3, 4}
AbsPrinter(p)
f := MyFloat(-10)
AbsPrinter(f)
package draw
type Point struct {
X, Y int
}
package main
import "draw"
var p draw.Point
package draw
typePointstruct {X,Yint
dist float64
}
type cache map[Point] float64
import "draw" can use the black names only.public.”func main() {
go expensiveComputation(x, y, z)
anotherExpensiveComputation(a, b, c)
}
func computeAndSend(ch chan int, x, y, z int) {
ch <- expensiveComputation(x, y, z)
}
func main() {
ch := make(chan int)
go computeAndSend(ch, x, y, z)
v2 := anotherExpensiveComputation(a, b, c)
v1 := <-ch
fmt.Println(v1, v2)
}
a.c includes b.h, which includes c.h, which includes d.h.#include <stdio.h> reads 360 lines from 9 files.#include <iostream> reads 25,326 lines from 131 files.#include <Carbon/Carbon.h> reads 124,730 lines from 689 files.package gui
import "draw"
type Mouse struct {
Loc draw.Point
Buttons uint
}
gui summarizes the necessary part of draw (just Point).gui summarizes the necessary part of draw (just Point). Pseudo-object:package gui
type draw.Point struct {
X, Y int
}
type gui.Mouse struct {
Loc draw.Point
Buttons uint
}
gui compiles without consulting draw or its dependencies.import "fmt" reads one file: 184 lines summarizing types from 7 packages.