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

The Awesomeness of Go

Apr 11, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Awesomeness of Go

The Awesomeness of Go

Igor Lankin DevFest Karlsruhe, Nov 2016

Page 2: The Awesomeness of Go

C#, Java, Java Script, …

full-time GO (waipu.tv )

2

Igor Lankin

Software Developer @ inovex

Page 3: The Awesomeness of Go

3

What is Go?

Page 4: The Awesomeness of Go

An Awesome Programming Language

4

Page 5: The Awesomeness of Go

5

Imagine

Robert Griesemer

RobPike

Ken Thompson

2007

Sep 21

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

Page 6: The Awesomeness of Go

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

Page 7: The Awesomeness of Go

slow, clumsy developmentpoor concurrency supportpoor toolingslow compilation

7

ProblemsLanguages did not adapt (well)

Page 8: The Awesomeness of Go

8

New Language

Robert Griesemer

RobPike

Ken Thompson

2007

Sep 21

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

Page 9: The Awesomeness of Go

make programming fun again

higher productivity

modern language: gc, networking, concurrency

9

1. Awesome By DesignGoal: Create an Awesome Language

Page 10: The Awesomeness of Go

10

Two Years Later

Robert Griesemer

RobPike

Ken Thompson

2007

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

2009

Page 11: The Awesomeness of Go

11

Birth of GoNovember 10, 2009

Page 12: The Awesomeness of Go

12

2. Awesome Mascot: GopherBy Renée French

Page 13: The Awesomeness of Go

native language with "scripty" feeling

statically typed, object oriented (kinda)

simple, pragmatic, efficient

built for scalability, multiprocessing, networking

13

Awesome ResultGo

Page 14: The Awesomeness of Go

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

Page 15: The Awesomeness of Go

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

Page 16: The Awesomeness of Go

16

Tabs vs Spaces

Page 17: The Awesomeness of Go

standardized formatting

no style guide

automatic code formatting (> go fmt)

no choice (really)

17

4. End of the Holy WarTABS!

Page 18: The Awesomeness of Go

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

Page 19: The Awesomeness of Go

19

Visualizing Concurrencygotrace: Fan-In

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

Page 20: The Awesomeness of Go

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

Page 21: The Awesomeness of Go

21

7. Awesomely Popular

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

Page 22: The Awesomeness of Go

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!

Page 23: The Awesomeness of Go

~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++

Page 24: The Awesomeness of Go

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

24

Page 25: The Awesomeness of Go

comprehensible concurrency, that keeps you sane

(mostly)

1. lightweight threads (goroutines)

2. safe communication (channels)

25

9. Awesome for Concurrencybuilt-in support

Page 26: The Awesomeness of Go

26

go doSomething()

goroutines

Page 27: The Awesomeness of Go

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

Page 28: The Awesomeness of Go

28

Page 29: The Awesomeness of Go

29

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

Page 30: The Awesomeness of Go

30

Communicating Sequential Processes (CSP)

Interaction between concurrent systems (T. Hoare, 1977)

Channel

Page 31: The Awesomeness of Go

31

Page 32: The Awesomeness of Go

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-

Page 33: The Awesomeness of Go

33

goroutines + channels = <3

very powerful concept

easy to use

safe communication

comprehensible concurrency, that keeps you sane

(mostly)

Page 34: The Awesomeness of Go

pragmatic attitude

remove waste (language, tools, libraries)

keep things small, comprehensible (minimalistic)

lets you focus on the problem

34

10. Awesomely PragmaticKeep it simple

Page 35: The Awesomeness of Go

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

Page 36: The Awesomeness of Go

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"

Page 37: The Awesomeness of Go

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

Page 38: The Awesomeness of Go

Vielen Dank

Igor Lankin

Software Developer

inovex GmbH

Ludwig-Erhard-Allee 6

76131 Karlsruhe

@theiigorr