Golang vs Ruby

24
GOLANG VS RUBY MICHAŁ KONARSKI 1

Transcript of Golang vs Ruby

Page 1: Golang vs Ruby

GOLANG VS RUBYMICHAŁ KONARSKI

1

Page 2: Golang vs Ruby

2

0,75%

1,5%

2,25%

3%

2012 2013 2014 2015 2016 2017

Page 3: Golang vs Ruby

3

POPULARITY OF GO

0,75%

1,5%

2,25%

3%

2012 2013 2014 2015 2016 2017

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

Page 4: Golang vs Ruby

WHO AM I? 4

u2i

Ruby developer @

Page 5: Golang vs Ruby

5

Page 6: Golang vs Ruby

RESERVED KEYWORDS 6

0

45

90

135

180

JAVASCRIPT C# C++ JAVA RUBY C GO

http://stackoverflow.com/questions/4980766/reserved-keywords-count-by-programming-language

Page 7: Golang vs Ruby

7

dynamic

interpreted (MRI)

static

compiled

object oriented

reflective concurrent

structured

garbage collected garbage collected

Page 8: Golang vs Ruby

STATICALLY TYPED DUCK TYPING

8

Page 9: Golang vs Ruby

9typeAnimalinterface{Speak()string

}

typeDogstruct{ageint32

}

func(dDog)Speak()string{return"Woof!"

}

funcSaySomething(aAnimal){ fmt.Println(a.Speak())}

dog:=Dog{}SaySomething(dog)

Page 10: Golang vs Ruby

000 DESIGN

10

Page 11: Golang vs Ruby

11Vehicle

Car Truck

PetrolCar PetrolTruck

ElectricCar ElectricTruck

Page 12: Golang vs Ruby

COMPOSITION OVER INHERITANCE

12

Page 13: Golang vs Ruby

13

Vehicle

Engine

Body

PetrolEngine

ElectricEngine

Car

Truck

Page 14: Golang vs Ruby

14

typeEngineinterface{start()}

typePetrolEnginestruct{}typeElectricEnginestruct{}

typeBodyinterface{weight()int32}

typeCarstruct{}typeTruckstruct{}

typeVehiclestruct{EngineBody}

vehicle:=Vehicle{Engine:PetrolEngine{},Body:Truck{}}vehicle.start()vehicle.weight()

Page 15: Golang vs Ruby

CONCURRENCY

15

Page 16: Golang vs Ruby

DON'T COMMUNICATE BY SHARING MEMORY, SHARE MEMORY BY COMMUNICATING.

16

Page 17: Golang vs Ruby

channel

channel

channel

17

Go process

goroutine goroutine

goroutine goroutine

goroutine goroutine

Page 18: Golang vs Ruby

18

result:=<-ch

funcHeavyComputations(){...

}

ch<-result

chchanint32

ch:=make(chanint32)

goHeavyComputations(ch)

//dootherthings

Page 19: Golang vs Ruby

19

THERE IS NOTHING EXCEPTIONAL IN EXCEPTIONS

Page 20: Golang vs Ruby

20

iferr!=nil{log.Fatal(err)returnerr

}

f,err:=os.Open(“filename.ext")

//dosomethingwiththefile

Page 21: Golang vs Ruby

21

GO FMT NO MORE CODE STYLE WARS

Page 22: Golang vs Ruby

22

Page 23: Golang vs Ruby

“LEARN AT LEAST ONE NEW LANGUAGE EVERY YEAR”

23

David Thomas and Andrew Hunt

Page 24: Golang vs Ruby

24@mjkonarski [email protected] blog.u2i.com

THANKS!