S
Go Lang
Ravi
Programming Model
Go concurrency motto:
"Do not communicate by sharing memory;
instead, share memory by communicating”
Quick Feature List
S Explicit support for concurrent programming.
S Compiled
S It is strongly typed and garbage-collected. Static typing
without too much keyboard typing
S High-level code when you want
S Low-level code when you want
Few Syntax
Demo
Concurrency + Parallelism
Go supports concurrency
S Go provides:
S concurrent execution (goroutines)
S synchronization and messaging (channels)
S multi-way concurrent control (select)
S “Lightweight”
S Starting 10,000 goroutines on MacBook Pro took 22ms
S Allocated memory increased by 3,014,000 bytes (301 bytes per
goroutine)
Goroutines
S Goroutines are multiplexed onto OS threads as required.
S When a goroutine blocks, that thread blocks but no other
goroutine blocks.
go foo()
go logger.Printf("Hello, %s!", who)
go func() {
logger.Printf("Hello, %s!", who)
...
}()
Channels
Channels are typed values that allow goroutines to synchronize
and exchange information.
// synchronous chan of ints
c := make(chan int)
// buffered chan of pointers to Request
c := make(chan *Request, 100
Communication
Quick syntax review
c := make(chan bool)– Makes an unbuffered channel of
bools
c <- x – Sends a value on the channel
<- c – Waits to receive a value on the channel
x = <- c – Waits to receive a value and stores it inx
x, ok = <- c – Waits to receive a value;okwill be false if
channel is closed and empty.
Multiple goroutines can send
on the same channel
S Go's Concurrency
S Built-in! Lightweight threads, no callback hell
S Readable, top-down code
S So easy to write servers
S for { conn, err := listener.Accept() // check err go serve(conn)
}
S Goroutine-per-request can scale
Use Cases
S Cloud infrastructure
S Go: the emerging language of cloud infrastructure
S Docker, Packer
S CoreOS’s etcd and fleet
S Ubuntu Juju, Mozilla Heka, Apcera’s NATS, gnatsd
S Mobile
S Go runs on ARM
S minux's iOS port of Go
S Camlistore child process, goandroid
S Audio synthesis
S https://github.com/nf/sigourney
S Language complexity
Java 8 language spec is a 780 page PDF (lol, seriously?).
http://docs.oracle.com/javase/sp...
Scala language spec is a 191 page PDF.
http://www.scala-lang.org/docu/f...
The Go language spec is webpage that prints as a 51 page PDF.
http://golang.org/ref/spec
Defining a language is not the same as learning how to use a language,
but it is a proxy for how much there is to learn (or how much there is to
confuse you when reading someone else's code).

Go Lang

  • 1.
  • 2.
    Programming Model Go concurrencymotto: "Do not communicate by sharing memory; instead, share memory by communicating”
  • 3.
    Quick Feature List SExplicit support for concurrent programming. S Compiled S It is strongly typed and garbage-collected. Static typing without too much keyboard typing S High-level code when you want S Low-level code when you want
  • 6.
  • 7.
  • 8.
  • 9.
    Go supports concurrency SGo provides: S concurrent execution (goroutines) S synchronization and messaging (channels) S multi-way concurrent control (select) S “Lightweight” S Starting 10,000 goroutines on MacBook Pro took 22ms S Allocated memory increased by 3,014,000 bytes (301 bytes per goroutine)
  • 10.
    Goroutines S Goroutines aremultiplexed onto OS threads as required. S When a goroutine blocks, that thread blocks but no other goroutine blocks. go foo() go logger.Printf("Hello, %s!", who) go func() { logger.Printf("Hello, %s!", who) ... }()
  • 11.
    Channels Channels are typedvalues that allow goroutines to synchronize and exchange information. // synchronous chan of ints c := make(chan int) // buffered chan of pointers to Request c := make(chan *Request, 100
  • 12.
  • 13.
    Quick syntax review c:= make(chan bool)– Makes an unbuffered channel of bools c <- x – Sends a value on the channel <- c – Waits to receive a value on the channel x = <- c – Waits to receive a value and stores it inx x, ok = <- c – Waits to receive a value;okwill be false if channel is closed and empty.
  • 14.
    Multiple goroutines cansend on the same channel
  • 15.
    S Go's Concurrency SBuilt-in! Lightweight threads, no callback hell S Readable, top-down code S So easy to write servers S for { conn, err := listener.Accept() // check err go serve(conn) } S Goroutine-per-request can scale
  • 16.
    Use Cases S Cloudinfrastructure S Go: the emerging language of cloud infrastructure S Docker, Packer S CoreOS’s etcd and fleet S Ubuntu Juju, Mozilla Heka, Apcera’s NATS, gnatsd
  • 17.
    S Mobile S Goruns on ARM S minux's iOS port of Go S Camlistore child process, goandroid S Audio synthesis S https://github.com/nf/sigourney
  • 18.
    S Language complexity Java8 language spec is a 780 page PDF (lol, seriously?). http://docs.oracle.com/javase/sp... Scala language spec is a 191 page PDF. http://www.scala-lang.org/docu/f... The Go language spec is webpage that prints as a 51 page PDF. http://golang.org/ref/spec Defining a language is not the same as learning how to use a language, but it is a proxy for how much there is to learn (or how much there is to confuse you when reading someone else's code).

Editor's Notes

  • #19 http://www.quora.com/Go-programming-language/Scala-vs-Go-Could-people-help-compare-contrast-these-on-relative-merits-demerits