The Awesomeness of Go Igor Lankin DevFest Karlsruhe, Nov 2016
Igor Lankin Software Developer @ inovex C#, Java, Java Script, full-time GO (waipu.tv ) 2
What is Go? 3
An Awesome Programming Language 4
Imagine 2007 Awesome Language!!! Sep 21 Robert Griesemer Rob Pike Ken Thompson 5
Why? The World has Changed multicore processors networked systems massive computation clusters tens of millions of lines of code web programming see Go at Google: Language Design in the Service of Software Engineering https://talks.golang.org/2009/go_talk-20091030.pdf 6
Problems Languages did not adapt (well) slow, clumsy development poor concurrency support poor tooling slow compilation 7
New Language 2007 Awesome Language!!! Sep 21 Robert Griesemer Rob Pike Ken Thompson 8
1. Awesome By Design Goal: Create an Awesome Language make programming fun again higher productivity modern language: gc, networking, concurrency 9
Two Years Later 2007 2009 Awesome Language!!! Robert Griesemer Rob Pike Ken Thompson 10
Birth of Go November 10, 2009 11
2. Awesome Mascot: Gopher By Renée French 12
Awesome Result Go native language with "scripty" feeling statically typed, object oriented (kinda) simple, pragmatic, efficient built for scalability, multiprocessing, networking 13
Examples package main import "fmt" type Rect struct { } Width, Height int func main() { sum := 0 for i := 0; i < 10; i++ { if i%2 == 0 { fmt.println(i) sum += i } } fmt.println(sum) } https://play.golang.org/p/6hcgnbt8se func (r *Rect) Area() int { return r.width * r.height } rect := Rect{6, 7} fmt.printf( %v has an area of %d\n, rect, rect.area()) https://play.golang.org/p/vhnwvfy2wl 14
3. Awesomely Readable clean, concise syntax reduced typing no stuttering: foo.foo *myfoo = new foo.foo(foo.foo_init) //?? flat type system clear control flow standardized formatting 15
Tabs vs Spaces 16
4. End of the Holy War TABS! standardized formatting no style guide automatic code formatting (> go fmt) no choice (really) 17
5. Awesome Tooling fast compiler (go build) dependency management (go get) testing, coverage, benchmarks (go test) profiler, static code analysis (go test) documentation, formatting (go doc, go fmt) great editors: vs code, sublime, atom, intellij awesome 3rd-party tools 18
Visualizing Concurrency gotrace: Fan-In https://divan.github.io/posts/go_concurrency_visualize/ 19
6. Awesome Community Share all the code fast-growing open-source libraries, tools, projects easy to share and reuse: import "github.com/aws/aws-sdk-go/aws" docs: godoc.org/github.com/aws/aws-sdk-go/aws github.com/avelino/awesome-go golanglibs.com 20
7. Awesomely Popular http://www.tiobe.com/tiobe-index/ 21
Who is using Go? Cool Folks Only! inovex GmbH, waipu.tv (exaring) Google: Youtube, kubernetes, dl.google.com Apple, Twitter, docker, Dropbox, SoundCloud, github.com/golang/go/wiki/gousers Popular among pythoners, IT-engineers 22
8. Awesome Performance Java < Go < C++ ~10-20% faster in v1.7 (amd64) x% faster in v1.8? (Jan 2017) compiled, garbage-collected superior concurrency => better CPU utilization 23
The End Of Moors Law http://philosophyworkout.blogspot.de/2016/01/a-decade-of-economic-stagnation-looms.html 24
9. Awesome for Concurrency built-in support comprehensible concurrency, that keeps you sane (mostly) 1. lightweight threads (goroutines) 2. safe communication (channels) 25
goroutines go dosomething() 26
func say(text string, delay int) { time.sleep(time.duration(delay) * time.second) fmt.println(text) } func main() { go say("let's go!", 3) go say("ho!", 2) go say("hey!", 1) fmt.println("waiting...") time.sleep(4 * time.second) } https://play.golang.org/p/lmiix-poz0 27
28
Do not communicate by sharing memory; share memory by communicating. - Rob Pike 29
Communicating Sequential Processes (CSP) Interaction between concurrent systems (T. Hoare, 1977) Channel 30
31
var ch = make(chan string) func say(text string, delay int) { time.sleep(time.duration(delay) * time.second) ch <- text } func main() { go consume() go say("let's go!", 3) go say("ho!", 2) go say("hey!", 1) func consume() { for { message := <-ch fmt.println(message) } } } time.sleep(4 * time.second) https://play.golang.org/p/wnslkutrd- 32
goroutines + channels = <3 very powerful concept easy to use safe communication comprehensible concurrency, that keeps you sane (mostly) 33
10. Awesomely Pragmatic Keep it simple pragmatic attitude remove waste (language, tools, libraries) keep things small, comprehensible (minimalistic) lets you focus on the problem 34
11. Awesome for Web Services And more not only for infrastructure cool frameworks for web services small, simple, beautiful but you can also build complex monoliths, too ;) 35
Everything Awesome? "90% Perfect, 100% of the time" Missing features: generics, thread-safe data structures May be confusing: slices, nil, pointers, range variable You need to think differently Modelling can be tricky But it still is pretty awesome! ;) 36
12. Awesomely Easy to Start golang.org welcome/ - A Tour of Go faq/ - FAQ doc/effective_go.html - Deep Dive play.golang.org gobyexample.com - Examples 37
Vielen Dank Igor Lankin Software Developer inovex GmbH Ludwig-Erhard-Allee 6 76131 Karlsruhe @theiigorr