際際滷

際際滷Share a Scribd company logo
Why Scala?
And let's take a tour of it
#1 Hanoi's Scala Meetup
11/2015
TungNT
tung_nt@septeni-technology.jp
N i dung畛
 Gi i thi u畛 畛
 Nh ng n辿t n i b t畛 畛 畉
 H ng  i t ng動畛 畛 動畛
 Basic Collection
 L p tr狸nh hm畉
Gi i Thi u畛 畛
About me
 Nguy n Thanh T湛ng - Software Developer t i Septeni畛 畉
Technolgoy
 Ng担n ng : C, Java, C#, PHP v畛 Scala cho hi n t i畛 畉
 Quan t但m  n:畉
 Scala, Angularjs, React...
 C叩c ki n tr炭c ph n m m畉 畉 畛
 Domain Driven Design
 Reactive web
 Entrepreneurship
M t ng担n ng m kh担ng nh h ng  n畛 畛 畉 動畛 畉
c叩ch b n ngh挑 v l p tr狸nh, th狸 n坦 kh担ng畉 畛 畉
叩ng  h c *畛 畛
Alan Perlis, nh khoa h c m叩y t鱈nh畛
*A language that doesn't affect the way you think about programming, is not worth knowing.
Th担ng tin s l c董 動畛
 Scala = Scalable Language
  c動畛 Martin Odersky t o ra nm 2003畉 t i畉 EPFL, Th y畛
S畛
  c d ch ra m達 Java Bytecode v ch y tr棚n JVM動畛 畛 畉
 C坦 th t叩i s d ng c叩c th vi n c a Java畛 畛 畛 動 畛 畛
 C炭 ph叩p u ti棚n s ng n g n動 畛 畉 畛
 H tr l p tr狸nh h ng  i t ng l n l p tr狸nh hm畛 畛 畉 動畛 畛 動畛 畉 畉
Th担ng tin s l c (2)董 動畛
 Scala = Java's speed + Ruby's syntax
 H tr t t Realtime/Reactive Web, Distributed System, Big畛 畛 畛
Data v i c叩c th vi n Future (built-in), Actor, Akka, Spark...畛 動 畛
 C叩c c担ng ty ang s d ng Scala:畛 畛
 Apple
 LinkedIn
 Twitter
 Foursquare
 Netflix
 Tumblr
 ...
Scala vs Java
Trang ch畛
http://www.scala-lang.org/
Tools & IDE
S叩ch n i b t畛 畉
H sinh th叩i畛
Ti nguy棚n tham kh o畉
 Official doc:
 http://www.scala-lang.org/documentation/
 Twitter's Scala School:
 https://twitter.github.io/scala_school/index.html
 Coursera (Online Course):
 https://www.coursera.org/course/progfun
 Awesome Scala:
 https://github.com/lauris/awesome-scala
N辿t n i b t畛 畉
Val vs Var
 Val khai b叩o bi n d i d ng Immutable = Read Only畉 動畛 畉
 Var khai b叩o bi n d i d ng Mutable = Read + Write畉 動畛 畉
Pattern Matching
 G n gi ng c u tr炭c switch-case trong ng担n ng畉 畛 畉 畛
kh叩c. Tuy nhi棚n...
 Uy n chuy n khi lm vi c v i Option type, Case畛 畛 畛 畛
Class thay ch d湛ng c v i primative type nh畛 畛 動
Java, C...
Option type
 L container ch a 1  i t ng m trong 坦:畛 畛 動畛
 C坦 gi叩 tr ~> Some(object)畛
 R ng ~> None畛
 L s thay th null trong Java v ng担n ng畛 畉 畛
kh叩c
 K t h p  c v i Pattern Matching畉 畛 動畛 畛
Closure
 L c叩ch khai b叩o hm m gi叩 tr tr v c坦 ph畛 畉 畛 畛
thu c vo bi n b棚n ngoi scope (d湛 kh担ng畛 畉
 c truy n qua  i s c a hm)動畛 畛 畛 畛 畛
Lazy val
 L c叩ch khai b叩o m k t qu ch t鱈nh to叩n v畉 畉 畛
tr v khi n坦  c g i  n畉 畛 動畛 畛 畉
Implicit
 Tr狸nh bi棚n d ch s t  ng t狸m ki m trong ng畛 畉 畛 畛 畉 畛
c nh(context) thnh ph n  c khai b叩o畉 畉 動畛
implicit
 Implicit c坦 nh ng thnh ph n g m:畛 畉 畛
 Implicit Conversion
 Implicit Parameters
Implicit (2)
H ng  i t ng trong動畛 畛 動畛
Scala
H tr  y  OOP畛 畛 畉 畛
 M i th trong Scala  u l畛 畛 畛 Object
 Kh担ng c坦 primitive type
 Kh担ng c坦 c叩c to叩n t ~> t t c  u l c叩c method畛 畉 畉 畛
 kh担ng c坦 static
C但y ph但n h畛
Class
Object
 L m t Singleton object畛
 Static theo c叩ch c a Scala畛
Case Class
 T  ng sinh getter/setter cho  i s畛 畛 畛 畛
 T  ng  nh ngh挑a c叩c method hashcode, equals v copy畛 畛 畛
 C坦 th s d ng trong pattern matching畛 畛 畛
Traits
 Scala Traits = Java interface + Ruby's mixin
Basic Collection trong
Scala
Lists & Set
 Lists
 Set
 Kh担ng c坦 ph n t tr湛ng畉 畛
Tuples
 Nh坦m c叩c ph n t ri棚ng l l i thnh 1 t p h p畉 畛 畉 畉 畉 畛
 Truy c p ph n t qua c炭 ph叩p ._畉 畉 畛
 C坦 th s d ng v i Pattern Matching畛 畛 畛 畛
Map
 L u tr theo d ng key  value動 畛 畉
 C坦 th l u value d i d ng 1 Map kh叩c ho c 1畛 動 動畛 畉 畉
function
L p tr狸nh hm trong Scala畉
Higher-Order Functions
 M t function c坦 th nh n  i s l 1 function畛 畛 畉 畛 畛
kh叩c ho c tr v k t qu d i d ng 1 function畉 畉 畛 畉 畉 動畛 畉
Function Currying
Trong khoa h c m叩y t鱈nh, currying, ph叩t minh b i Moses Sch旦nfinkel v畛 畛
Gottlob Frege, l k thu t chuy n  i m t function m c坦 nhi u  i s sang畛 畉 畛 畛 畛 畛 畛 畛
1 function m ch c坦 m t  i s duy nh t (c叩c  i s kh叩c 達  c quy  nh畛 畛 畛 畛 畉 畛 畛 動畛 畛
b i curry). - wikipedia畛
VD:
 Tr c:動畛
 Sau:
Function Currying (2)
ng d ng th c t :畛 畛 畛 畉
 Ch  nh default:畛 畛
 D湛ng v i implicit:畛
Functional Combinators
 map
 return l i collection m i畉 畛

foreach
 Gi ng map nh ng kh担ng return g狸 c畛 動 畉

filter
 zip
Functional Combinators (2)
 partition
 find
Functional Combinators (3)
 foldLeft
 foldRight
Functional Combinators (4)
 reduceLeft / reduceRight
 G n gi ng fold, nh ng:畉 畛 動
 Kh担ng c n kh i t o ban  u, d湛ng ch鱈nh ph n t  u ti棚n畉 畛 畉 畉 畉 畛 畉
cho vi c ny (n辿m ra Exception n u collection r ng)畛 畉 畛
 VD:
 fold:
 reduce:
Functional Combinators (5)
 flatten
 dn ph ng 1 nested structure畉
 flatMap
 L s k t h p c a map v flatten畛 畉 畛 畛
V:
 Self type
 Monads
 Extractor Objects
 Sequence Comprehensions
 Package object
  c湛ng nhi u i u kh叩c n a畛 畛 畛
Ng i n i ti ng n坦i g狸?動畛 畛 畉
N u t担i ph i l a ch n m t ng担n ng  s d ng ngy nay ngoi Java, n坦 s l畉 畉 畛 畛 畛 畛 畛 畛 畛 畉
Scala (1)
James Gosling, cha  ng担n ng Java畉 畛
T担i c坦 th thnh th t m n坦i r ng n u m t ng i no 坦  a cho t担i cu n畛 畉 畉 畉 畛 動畛 動 畛
Programming in Scala c a Martin Odersky c湛ng Lex Spoon v Bill Venners畛
trong nm 2003 th狸 c坦 l t担i 達 ch a bao gi t o ra Groovy.畉 動 畛 畉 (2)
James Strachan, cha  ng担n ng畉 畛 Groovy
(1) If I were to pick a language to use today other than Java, it would be Scala
(2) I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 Id probably have never created Groovy.
Thank you

More Related Content

Why scala?

  • 1. Why Scala? And let's take a tour of it #1 Hanoi's Scala Meetup 11/2015 TungNT tung_nt@septeni-technology.jp
  • 2. N i dung畛 Gi i thi u畛 畛 Nh ng n辿t n i b t畛 畛 畉 H ng i t ng動畛 畛 動畛 Basic Collection L p tr狸nh hm畉
  • 3. Gi i Thi u畛 畛
  • 4. About me Nguy n Thanh T湛ng - Software Developer t i Septeni畛 畉 Technolgoy Ng担n ng : C, Java, C#, PHP v畛 Scala cho hi n t i畛 畉 Quan t但m n:畉 Scala, Angularjs, React... C叩c ki n tr炭c ph n m m畉 畉 畛 Domain Driven Design Reactive web Entrepreneurship
  • 5. M t ng担n ng m kh担ng nh h ng n畛 畛 畉 動畛 畉 c叩ch b n ngh挑 v l p tr狸nh, th狸 n坦 kh担ng畉 畛 畉 叩ng h c *畛 畛 Alan Perlis, nh khoa h c m叩y t鱈nh畛 *A language that doesn't affect the way you think about programming, is not worth knowing.
  • 6. Th担ng tin s l c董 動畛 Scala = Scalable Language c動畛 Martin Odersky t o ra nm 2003畉 t i畉 EPFL, Th y畛 S畛 c d ch ra m達 Java Bytecode v ch y tr棚n JVM動畛 畛 畉 C坦 th t叩i s d ng c叩c th vi n c a Java畛 畛 畛 動 畛 畛 C炭 ph叩p u ti棚n s ng n g n動 畛 畉 畛 H tr l p tr狸nh h ng i t ng l n l p tr狸nh hm畛 畛 畉 動畛 畛 動畛 畉 畉
  • 7. Th担ng tin s l c (2)董 動畛 Scala = Java's speed + Ruby's syntax H tr t t Realtime/Reactive Web, Distributed System, Big畛 畛 畛 Data v i c叩c th vi n Future (built-in), Actor, Akka, Spark...畛 動 畛 C叩c c担ng ty ang s d ng Scala:畛 畛 Apple LinkedIn Twitter Foursquare Netflix Tumblr ...
  • 11. S叩ch n i b t畛 畉
  • 13. Ti nguy棚n tham kh o畉 Official doc: http://www.scala-lang.org/documentation/ Twitter's Scala School: https://twitter.github.io/scala_school/index.html Coursera (Online Course): https://www.coursera.org/course/progfun Awesome Scala: https://github.com/lauris/awesome-scala
  • 14. N辿t n i b t畛 畉
  • 15. Val vs Var Val khai b叩o bi n d i d ng Immutable = Read Only畉 動畛 畉 Var khai b叩o bi n d i d ng Mutable = Read + Write畉 動畛 畉
  • 16. Pattern Matching G n gi ng c u tr炭c switch-case trong ng担n ng畉 畛 畉 畛 kh叩c. Tuy nhi棚n... Uy n chuy n khi lm vi c v i Option type, Case畛 畛 畛 畛 Class thay ch d湛ng c v i primative type nh畛 畛 動 Java, C...
  • 17. Option type L container ch a 1 i t ng m trong 坦:畛 畛 動畛 C坦 gi叩 tr ~> Some(object)畛 R ng ~> None畛 L s thay th null trong Java v ng担n ng畛 畉 畛 kh叩c K t h p c v i Pattern Matching畉 畛 動畛 畛
  • 18. Closure L c叩ch khai b叩o hm m gi叩 tr tr v c坦 ph畛 畉 畛 畛 thu c vo bi n b棚n ngoi scope (d湛 kh担ng畛 畉 c truy n qua i s c a hm)動畛 畛 畛 畛 畛
  • 19. Lazy val L c叩ch khai b叩o m k t qu ch t鱈nh to叩n v畉 畉 畛 tr v khi n坦 c g i n畉 畛 動畛 畛 畉
  • 20. Implicit Tr狸nh bi棚n d ch s t ng t狸m ki m trong ng畛 畉 畛 畛 畉 畛 c nh(context) thnh ph n c khai b叩o畉 畉 動畛 implicit Implicit c坦 nh ng thnh ph n g m:畛 畉 畛 Implicit Conversion Implicit Parameters
  • 22. H ng i t ng trong動畛 畛 動畛 Scala
  • 23. H tr y OOP畛 畛 畉 畛 M i th trong Scala u l畛 畛 畛 Object Kh担ng c坦 primitive type Kh担ng c坦 c叩c to叩n t ~> t t c u l c叩c method畛 畉 畉 畛 kh担ng c坦 static
  • 25. Class
  • 26. Object L m t Singleton object畛 Static theo c叩ch c a Scala畛
  • 27. Case Class T ng sinh getter/setter cho i s畛 畛 畛 畛 T ng nh ngh挑a c叩c method hashcode, equals v copy畛 畛 畛 C坦 th s d ng trong pattern matching畛 畛 畛
  • 28. Traits Scala Traits = Java interface + Ruby's mixin
  • 30. Lists & Set Lists Set Kh担ng c坦 ph n t tr湛ng畉 畛
  • 31. Tuples Nh坦m c叩c ph n t ri棚ng l l i thnh 1 t p h p畉 畛 畉 畉 畉 畛 Truy c p ph n t qua c炭 ph叩p ._畉 畉 畛 C坦 th s d ng v i Pattern Matching畛 畛 畛 畛
  • 32. Map L u tr theo d ng key value動 畛 畉 C坦 th l u value d i d ng 1 Map kh叩c ho c 1畛 動 動畛 畉 畉 function
  • 33. L p tr狸nh hm trong Scala畉
  • 34. Higher-Order Functions M t function c坦 th nh n i s l 1 function畛 畛 畉 畛 畛 kh叩c ho c tr v k t qu d i d ng 1 function畉 畉 畛 畉 畉 動畛 畉
  • 35. Function Currying Trong khoa h c m叩y t鱈nh, currying, ph叩t minh b i Moses Sch旦nfinkel v畛 畛 Gottlob Frege, l k thu t chuy n i m t function m c坦 nhi u i s sang畛 畉 畛 畛 畛 畛 畛 畛 1 function m ch c坦 m t i s duy nh t (c叩c i s kh叩c 達 c quy nh畛 畛 畛 畛 畉 畛 畛 動畛 畛 b i curry). - wikipedia畛 VD: Tr c:動畛 Sau:
  • 36. Function Currying (2) ng d ng th c t :畛 畛 畛 畉 Ch nh default:畛 畛 D湛ng v i implicit:畛
  • 37. Functional Combinators map return l i collection m i畉 畛 foreach Gi ng map nh ng kh担ng return g狸 c畛 動 畉 filter zip
  • 38. Functional Combinators (2) partition find
  • 39. Functional Combinators (3) foldLeft foldRight
  • 40. Functional Combinators (4) reduceLeft / reduceRight G n gi ng fold, nh ng:畉 畛 動 Kh担ng c n kh i t o ban u, d湛ng ch鱈nh ph n t u ti棚n畉 畛 畉 畉 畉 畛 畉 cho vi c ny (n辿m ra Exception n u collection r ng)畛 畉 畛 VD: fold: reduce:
  • 41. Functional Combinators (5) flatten dn ph ng 1 nested structure畉 flatMap L s k t h p c a map v flatten畛 畉 畛 畛
  • 42. V: Self type Monads Extractor Objects Sequence Comprehensions Package object c湛ng nhi u i u kh叩c n a畛 畛 畛
  • 43. Ng i n i ti ng n坦i g狸?動畛 畛 畉 N u t担i ph i l a ch n m t ng担n ng s d ng ngy nay ngoi Java, n坦 s l畉 畉 畛 畛 畛 畛 畛 畛 畛 畉 Scala (1) James Gosling, cha ng担n ng Java畉 畛 T担i c坦 th thnh th t m n坦i r ng n u m t ng i no 坦 a cho t担i cu n畛 畉 畉 畉 畛 動畛 動 畛 Programming in Scala c a Martin Odersky c湛ng Lex Spoon v Bill Venners畛 trong nm 2003 th狸 c坦 l t担i 達 ch a bao gi t o ra Groovy.畉 動 畛 畉 (2) James Strachan, cha ng担n ng畉 畛 Groovy (1) If I were to pick a language to use today other than Java, it would be Scala (2) I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 Id probably have never created Groovy.