Golang from Scala developer’s perspective
-
Upload
svetlana-bozhko -
Category
Technology
-
view
1.844 -
download
0
Transcript of Golang from Scala developer’s perspective
![Page 1: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/1.jpg)
Golang from Scala developer’s perspective
![Page 2: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/2.jpg)
About me
Svetlana BozhkoBackend Scala Developer @ Adform
![Page 3: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/3.jpg)
The goalIs Go really so bad imperative?
![Page 4: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/4.jpg)
Content
Short intro into GoTooling FP vs. GoIMHO
![Page 5: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/5.jpg)
Usagehttps://github.com/golang/go/wiki/GoUsers
![Page 6: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/6.jpg)
![Page 7: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/7.jpg)
How to start?http://tour.golang.org/http://golangshow.com/
![Page 8: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/8.jpg)
GoGood parts
![Page 9: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/9.jpg)
Go is actually a pretty simple language!
![Page 10: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/10.jpg)
Even too simple for 2015
![Page 11: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/11.jpg)
![Page 12: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/12.jpg)
Advanced GC
![Page 13: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/13.jpg)
“Build time matters more than anything else” -‐ Rob Pike
![Page 14: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/14.jpg)
gofmt
![Page 15: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/15.jpg)
Quite good toolsbuild-‐in (version, get, build, …)editors (vim, intellij, sublime, …)
![Page 16: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/16.jpg)
Concurrency• Channels
send data between threads easily, asynchronously or synchronously
• GoRoutinesspin up another thread, just like that!
![Page 17: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/17.jpg)
No Language Is Perfect...
![Page 18: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/18.jpg)
Go Mentality• Smallest possible feature set• It’s okay to copy some code
• Productivity instead of hyper-‐elegant code
![Page 19: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/19.jpg)
Let’s get rid of• Implicit numeric conversion (int != int32)• ‘Implements’ keyword• ‘Classes’• Constructor/destructor• Function overloading• Pointer arithmetic • Exceptions and try/catch• Generics• …
![Page 20: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/20.jpg)
Strict compilerwhich interrupts you sometimes
![Page 21: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/21.jpg)
Wait, Go has ‘goto’?
![Page 22: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/22.jpg)
Wait, how to debug?GDB, but it’s not very good way
![Page 23: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/23.jpg)
Dependency management
vendor (since 1.5)
![Page 24: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/24.jpg)
FP vs. Go
![Page 25: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/25.jpg)
Wikipedia:“Functional programming is a programming paradigm — a style of building the structure and elements of computer programs — that treats computation as the evaluation of mathematical functions and avoids changing-‐state and mutable data.”
![Page 26: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/26.jpg)
What it means?No mutable data (no side effect)
No mutable state (no implicit, hidden state)Same result returned by functions called with the same inputs
Functions are pure functions in the mathematical sense
![Page 27: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/27.jpg)
Advantages?
Cleaner codeReferential transparency
![Page 28: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/28.jpg)
Referential transparencyMemoizationCache resultsIdempotenceModularizationWe have no stateEase of debugging
Functions are isolated and very easy to debug
![Page 29: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/29.jpg)
Referential transparency
ParallelizationFunctions calls are independent
We can parallelize in different process/CPUs/computers/...
res = func1(a, b) + func2(a, c)
![Page 30: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/30.jpg)
Referential transparency
With no shared data, concurrency gets a lot simpler:No semaphoresNo monitors No locks
No race-‐conditionsNo dead-‐locks
![Page 31: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/31.jpg)
NonethelessGolang has built-‐in “sync” package with mutexes
![Page 32: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/32.jpg)
Don’t Update, Create!
![Page 33: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/33.jpg)
String
![Page 34: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/34.jpg)
Arrays
![Page 35: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/35.jpg)
Maps
![Page 36: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/36.jpg)
Higher order functions
![Page 37: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/37.jpg)
FP librarieshttps://github.com/yanatan16/itertools
https://github.com/tobyhede/go-‐underscore
![Page 38: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/38.jpg)
Higher order functions
![Page 39: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/39.jpg)
Map
![Page 40: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/40.jpg)
Filter
![Page 41: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/41.jpg)
Reduce
![Page 42: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/42.jpg)
Closures
![Page 43: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/43.jpg)
Currying and Partial Functions
![Page 44: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/44.jpg)
Eager vs Lazy Evaluation
Golang channels and goroutines enable the creation of generators that could be a way to have
lazy evaluation
![Page 45: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/45.jpg)
Recursion
![Page 46: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/46.jpg)
FP & OOP
It is possible do FP in OOP? Yes it is!
OOP is orthogonal to FP. At least in theory…
![Page 47: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/47.jpg)
Exercise!
What is the sum of the first 10 natural number whose square value is divisible by 2?
![Page 48: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/48.jpg)
Exercise!Imperative Functional
![Page 49: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/49.jpg)
Learn at least one functional language
It will open your mind to a new paradigm becoming you a better programmer
![Page 50: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/50.jpg)
Conclusion
Technologies are awesome! The problem is people how we use them.
![Page 52: Golang from Scala developer’s perspective](https://reader034.fdocuments.in/reader034/viewer/2022052117/5870637d1a28ab48378b46d3/html5/thumbnails/52.jpg)
Links
https://golang-‐ru.slack.com/messageshttps://www.youtube.com/watch?list=PLPHSBhlVt
TyfwIKn7r_a5xkzzMu-‐iey-‐w&v=cGXorQkw3JE