"Go is efficient, scalable, and productive. Some programmers find it fun to work in; others find it unimaginative, even boring."
"Most interesting thing about Go is that it's not object oriented or procedural or functional, it's its own new exciting thing"
"with Go I was able to pick up programming / CS concepts rather quickly, enjoy the process, and learn a ton of things in the meantime"
"Although Go is quite a small language, it is a very rich and expressive language (as measured in syntactic constructs, concepts, and idioms), so there is a surprising amount to learn."
"Even if you’re a dynamic language zealot, I bet you’d be shocked how productive you can be with a statically typed language like Go."
"Golang is a very pleasant language to get systems-y things done in. I'm fond of saying that it's not an amazing language, but is an amazing programming tool."
"When launching a new language it is important that the target audience be able to learn it quickly; rooting Go in the C family helps make sure that young programmers, most of whom know Java, JavaScript, and maybe C, should find Go easy to learn."
$ tar -C /usr/local -xzf go1.7.3.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin
$ export GOPATH=$HOME/go
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
...
package main
...
"Go encourages you to perform software composition by composing individual pieces of Go packages as an application"
...
import "fmt"
...
...
func main() {
fmt.Println("Hello, 世界")
}
...
go get
go get github.com/Netflix/chaosmonkey
go run
go build
go fmt
func add(x int, y int) int
func ReadByte() (c byte, err error)
var c, python, java bool
var i, j int = 1, 2
In Go, := is for declaration + assignment
= is only for assignment
Can also be used for shorthand execution in if
type Vertex struct {
X, Y float64
}
func (v Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func main() {
v := Vertex{3, 4}
fmt.Println(v.Abs())
}
letters := [26]string{"a","b"........
letters := []string{"a","b"........
append()
m = map[string]int{}
m["route"] = 66
type Vertex struct {
X int
Y int
}
func main() {
v := Vertex{1, 2}
v.X = 4
fmt.Println(v.X)
}
For is Go's "while"
A defer statement defers the execution of a function until the surrounding function returns.
https://en.wikipedia.org/wiki/Communicating_sequential_processes
"Do not communicate by sharing memory; instead, share memory by communicating."
// A _goroutine_ is a lightweight thread of execution.
// Suppose we have a function call `f(s)`. Here's how
// we'd call that in the usual way, running it
// synchronously.
f("direct")
// To invoke this function in a goroutine, use
// `go f(s)`. This new goroutine will execute
// concurrently with the calling one.
go f("goroutine")
// You can also start a goroutine for an anonymous
// function call.
go func(msg string) {
fmt.Println(msg)
}("going")
// Our two function calls are running asynchronously in
// separate goroutines now, so execution falls through
// to here. This `Scanln` code requires we press a key
// before the program exits.
var input string
fmt.Scanln(&input)
fmt.Println("done")
"Channels are the pipes that connect concurrent goroutines."
https://github.com/mrf/go-for-php-code
go tool tour
|