Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Golang from Scala developer’s perspective

2,020 views

Published on

My talk from Functional Vilnius MeetUp #6.
http://www.functionalvilnius.lt/posts/2015-10-03-6th-meetup-announcement.html
Golang is becoming more and more popular. Most likely many of you have heard of its upgraded garbage collector and possibilities to work with lightweight threads – goroutines. Obviously, Golang is quite a good choice for server-side software oriented on a huge load. As Scala backend developer, I am a big fan of functional programming and actor model. Golang seems very promising, but from the first glance, its a totally imperative language. In my speech I’m going to tell about my experiments with Golang and attempt to use it as a functional language.

Published in: Technology

Golang from Scala developer’s perspective

  1. 1. Golang from  Scala   developer’s  perspective
  2. 2. About  me Svetlana  Bozhko Backend  Scala  Developer  @  Adform
  3. 3. The  goal Is  Go  really  so  bad imperative?
  4. 4. Content Short  intro  into  Go Tooling   FP  vs.  Go IMHO
  5. 5. Usage https://github.com/golang/go/wiki/GoUsers
  6. 6. How  to  start? http://tour.golang.org/ http://golangshow.com/
  7. 7. Go Good  parts
  8. 8. Go  is  actually  a  pretty   simple  language!
  9. 9. Even  too  simple  for  2015
  10. 10. Advanced  GC
  11. 11. “Build  time  matters  more   than  anything  else”  -­‐ Rob  Pike
  12. 12. gofmt
  13. 13. Quite  good  tools build-­‐in  (version,  get,  build,  …) editors  (vim,  intellij,  sublime,  …)
  14. 14. Concurrency • Channels send  data  between  threads  easily,   asynchronously  or  synchronously • GoRoutines spin  up  another  thread,  just  like  that!
  15. 15. No  Language  Is  Perfect...
  16. 16. Go  Mentality • Smallest  possible  feature  set • It’s  okay  to  copy  some  code   • Productivity  instead  of  hyper-­‐elegant  code
  17. 17. Let’s  get  rid  of • Implicit  numeric  conversion  (int !=  int32) • ‘Implements’  keyword • ‘Classes’ • Constructor/destructor • Function  overloading • Pointer  arithmetic   • Exceptions  and  try/catch • Generics • …
  18. 18. Strict  compiler which  interrupts  you  sometimes
  19. 19. Wait,  Go  has  ‘goto’?
  20. 20. Wait,  how  to  debug? GDB,  but  it’s  not  very  good  way
  21. 21. Dependency   management vendor  (since  1.5)  
  22. 22. FP  vs.  Go
  23. 23. 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.”  
  24. 24. 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
  25. 25. Advantages? Cleaner  code Referential  transparency
  26. 26. Referential  transparency Memoization Cache  results Idempotence Modularization We  have  no  state Ease  of  debugging Functions  are  isolated  and  very  easy  to  debug
  27. 27. Referential  transparency Parallelization Functions  calls  are  independent   We  can  parallelize  in  different  process/CPUs/computers/...   res  =  func1(a,  b)  +  func2(a,  c)
  28. 28. Referential  transparency With  no  shared  data,  concurrencygets  a  lot  simpler: No  semaphores No  monitors   No  locks No  race-­‐conditions No  dead-­‐locks
  29. 29. Nonetheless Golang has  built-­‐in  “sync”  package  with  mutexes
  30. 30. Don’t  Update,  Create!
  31. 31. String
  32. 32. Arrays
  33. 33. Maps
  34. 34. Higher  order  functions
  35. 35. FP  libraries https://github.com/yanatan16/itertools https://github.com/tobyhede/go-­‐underscore
  36. 36. Higher  order  functions
  37. 37. Map
  38. 38. Filter
  39. 39. Reduce
  40. 40. Closures
  41. 41. Currying  and  Partial   Functions
  42. 42. Eager  vs  Lazy  Evaluation Golang channels  and  goroutines enable  the   creation  of  generators  that  could  be  a  way  to  have   lazy  evaluation
  43. 43. Recursion
  44. 44. FP  &  OOP It  is  possible  do  FP  in  OOP?   Yes  it  is! OOP  is  orthogonal  to  FP.  At  least  in  theory…
  45. 45. Exercise! What  is  the  sum  of  the  first  10  natural  number   whose  square  value  is  divisible  by  2?
  46. 46. Exercise! Imperative Functional
  47. 47. Learn  at  least  one   functional  language It  will  open  your  mind  to  a  new  paradigm   becoming  you  a  better  programmer
  48. 48. Conclusion Technologies  are  awesome!   The  problem  is  people how  we  use  them.
  49. 49. Thank  you! Questions? Svetlana  Bozhko aka  @SBozhko http://devzen.ru/ svt.bozhko@gmail.com
  50. 50. Links https://golang-­‐ru.slack.com/messages https://www.youtube.com/watch?list=PLPHSBhlVt TyfwIKn7r_a5xkzzMu-­‐iey-­‐w&v=cGXorQkw3JE

×