the awesomeness of go

38
The Awesomeness of Go Igor Lankin DevFest Karlsruhe, Nov 2016

Upload: christina-rasimus

Post on 11-Apr-2017

53 views

Category:

Software


0 download

TRANSCRIPT

The Awesomeness of Go

Igor Lankin DevFest Karlsruhe, Nov 2016

C#, Java, Java Script, …

full-time GO (waipu.tv )

2

Igor Lankin

Software Developer @ inovex

3

What is Go?

An Awesome Programming Language

4

5

Imagine

Robert Griesemer

RobPike

Ken Thompson

2007

Sep 21

Awesome Language!!!Awesome Language!!!Awesome Language!!!

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

Why?The World has Changed

slow, clumsy developmentpoor concurrency supportpoor toolingslow compilation

7

ProblemsLanguages did not adapt (well)

8

New Language

Robert Griesemer

RobPike

Ken Thompson

2007

Sep 21

Awesome Language!!!Awesome Language!!!Awesome Language!!!

make programming fun again

higher productivity

modern language: gc, networking, concurrency

9

1. Awesome By DesignGoal: Create an Awesome Language

10

Two Years Later

Robert Griesemer

RobPike

Ken Thompson

2007

Awesome Language!!!Awesome Language!!!Awesome Language!!!

2009

11

Birth of GoNovember 10, 2009

12

2. Awesome Mascot: GopherBy Renée French

native language with "scripty" feeling

statically typed, object oriented (kinda)

simple, pragmatic, efficient

built for scalability, multiprocessing, networking

13

Awesome ResultGo

14

Examplespackage main

import "fmt"

func main() {sum := 0for i := 0; i < 10; i++ {

if i%2 == 0 {fmt.Println(i)sum += i

}}fmt.Println(sum)

}

type Rect struct { Width, Height int}

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/6hCgnBt8se https://play.golang.org/p/VHnwvfY2Wl

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

3. Awesomely Readable

16

Tabs vs Spaces

standardized formatting

no style guide

automatic code formatting (> go fmt)

no choice (really)

17

4. End of the Holy WarTABS!

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, intellijawesome 3rd-party tools

18

5. Awesome Tooling

19

Visualizing Concurrencygotrace: Fan-In

https://divan.github.io/posts/go_concurrency_visualize/

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

6. Awesome CommunityShare all the code

21

7. Awesomely Popular

http://www.tiobe.com/tiobe-index/

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

Who is using Go?Cool Folks Only!

~10-20% faster in v1.7 (amd64)

x% faster in v1.8? (Jan 2017)

compiled, garbage-collected

superior concurrency

=> better CPU utilization

23

8. Awesome PerformanceJava < Go < C++

The End Of Moors Lawhttp://philosophyworkout.blogspot.de/2016/01/a-decade-of-economic-stagnation-looms.html

24

comprehensible concurrency, that keeps you sane

(mostly)

1. lightweight threads (goroutines)

2. safe communication (channels)

25

9. Awesome for Concurrencybuilt-in support

26

go doSomething()

goroutines

27

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

28

29

“Do not communicate by sharing memory; share memory by communicating.”- Rob Pike

30

Communicating Sequential Processes (CSP)

Interaction between concurrent systems (T. Hoare, 1977)

Channel

31

32

var ch = make(chan string)

func say(text string, delay int) {time.Sleep(time.Duration(delay) * time.Second)ch <- text

}

func consume() {for {

message := <-chfmt.Println(message)

}}

func main() {go consume()

go say("let's go!", 3)go say("ho!", 2)go say("hey!", 1)

time.Sleep(4 * time.Second)}

https://play.golang.org/p/WnsLkutrd-

33

goroutines + channels = <3

very powerful concept

easy to use

safe communication

comprehensible concurrency, that keeps you sane

(mostly)

pragmatic attitude

remove waste (language, tools, libraries)

keep things small, comprehensible (minimalistic)

lets you focus on the problem

34

10. Awesomely PragmaticKeep it simple

not only for infrastructure

cool frameworks for web services

small, simple, beautiful

but you can also build complex monoliths, too ;)

35

11. Awesome for Web ServicesAnd more

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

Everything Awesome?"90% Perfect, 100% of the time"

welcome/ - A Tour of Go

faq/ - FAQ

doc/effective_go.html - Deep Dive

play.golang.org

gobyexample.com - Examples

37

12. Awesomely Easy to Startgolang.org

Vielen Dank

Igor Lankin

Software Developer

inovex GmbH

Ludwig-Erhard-Allee 6

76131 Karlsruhe

@theiigorr