tech talk - things i learned at scala days 2013
DESCRIPTION
Tech Talk I gave at my company for the things I learned at Scala Days 2013TRANSCRIPT
![Page 2: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/2.jpg)
Scala the **** out of NYC3 days event @ NYCScala Sunday @ meetup HQ: 8 talksShapeless workshop on Monday
![Page 3: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/3.jpg)
Hot TopicsScala 2.10Style of Scala*Asynchronous Programming - akkaBig Data / Streaming Data - SparkMacroPlay
![Page 4: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/4.jpg)
Keynote: Scala with Styleby Martin Odersky, creator of scala
![Page 5: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/5.jpg)
What is OOP good for?Fixed APIs with unknown implementations. e.g.Simula67 for simulation, Smalltalk for GUIObjects are characterized by state, identity andbehavior - Grady Booch
![Page 6: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/6.jpg)
OOP v.s. FP
![Page 7: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/7.jpg)
Guideline #1 Keep it simple
Simple Made Easy - Rich Hichey
![Page 8: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/8.jpg)
Guideline #2 Don't pack too much in one
expressionfind meaningful names for the intermediate results. It's
not easy but it's important
![Page 9: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/9.jpg)
Guideline #3 Prefer Functional
vals v.s. varsrecursions or combinators v.s. loopsimmutable v.s. mutable collectionstransformations v.s. CRUD*
![Page 10: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/10.jpg)
Guideline #4 But, don't diabolize local statesometimes, mutable gives better performancesometimes, mutable adds convenience
![Page 11: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/11.jpg)
vars v.s. valsvar interfaces = parseClassHeader()...if (isAnnotation) interfaces += ClassFileAnnotation
val parsedIfaces = parseClassHeader()...val interfaces = if (isAnnotation) parsedIfaces + ClassFileAnnotation else parsedIfaces
![Page 12: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/12.jpg)
loops v.s. combinatorsval totalPrice = items.map(_.price).sumval totalDiscount = items.map(_.discount).sum
![Page 13: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/13.jpg)
val (totalPrice, totalDiscount) = items.foldLeft((0.0, 0.0)) { case ((tprice, tdiscount), item) => (tprice + item.price, tdiscount + item.discount) }
var totalPrice, totalDiscount = 0.0for (item <- items) { totalPrice += item.price totalDiscount += item.discount}
![Page 14: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/14.jpg)
Guideline #5 Careful with mutable objects
val m = ArrayBuffer[Int]()
![Page 15: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/15.jpg)
Guideline #6 Don't stop improving too early
shrink code by factor of 10 + make it more readable atthe same timeclean and elegant solutions don't come to mind at thefirst timeit is fun to find better solutions
![Page 16: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/16.jpg)
Choice #1 Infix v.s. "."
![Page 17: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/17.jpg)
Choice #2 Alphabetic v.s. Symbolic
val xs = List("apples", "oranges", "pears")
xs.foldLeft("")((result, i) => result + i)
("" /: xs)((result, i) => result + i)
![Page 18: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/18.jpg)
Choice #3 Loop, recursion or combinators
try conbinators firstif it becomes too tedious, or efficiency is a big concern,try tail-recursionuse loop for simple case or for readability
![Page 19: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/19.jpg)
Choice #4 Procedures or "="
DON'T use procedure syntax
def method: Unit = { // operations}
![Page 20: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/20.jpg)
Choice #5 Private v.s. nested
use nested function to avoid passing parametersuse nested function for small functionsdon't nest too many levels
![Page 21: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/21.jpg)
Choice #6 pattern matching v.s. dynamic
dispatchthe expression problem, check out
, lecture 4.5 and 4.6scala class @ coursera
![Page 22: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/22.jpg)
Choice #7 type parameters v.s. abstract type
members
try type parameters firstavoid Animals[_]
a good article by Bill Venners
![Page 23: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/23.jpg)
Keynote: Scala in 2018by Rod Johnson, creator of Spring
![Page 24: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/24.jpg)
in 2018Java is still aliveEnterprise apps are using ScalaStartups are still NOT using Scala
![Page 25: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/25.jpg)
myths / pointsReadability over cleverness, LOC, FP, ...Scala needs coding standardScala needs to move slowerEmbracing instead of hating Java
![Page 26: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/26.jpg)
Any fool can write code that a computer can understand.Good programmers write code that human can
understand. - Martin Fowler
![Page 27: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/27.jpg)
Debugging is twice as hard as writing the code in the firstplace. Therefore, if you write the code as cleverly aspossible, you are, by definition, not smart enough to
debug it. - Brian Kernighan
![Page 28: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/28.jpg)
Asynchronous Programming
![Page 29: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/29.jpg)
asynchronous v.s. parallelwhat else?who's doing it?
![Page 30: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/30.jpg)
asynchronous v.s. batching
![Page 31: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/31.jpg)
pitfall: thread pool?for tomcat, one thread handles one request
![Page 32: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/32.jpg)
pitfall: back pressure
![Page 33: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/33.jpg)
pitfall: performance v.s. scaling issue
![Page 34: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/34.jpg)
pitfall: theory v.s. realitycost of thread context switch# of threads v.s. # of CPUswhere is the bottleneck?
![Page 35: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/35.jpg)
Some thoughts about our system
![Page 36: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/36.jpg)
Upgrade to scala 2.10
![Page 37: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/37.jpg)
Use akkaasynchronous programmingfault tolerancemodular design
![Page 38: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/38.jpg)
Use case class for data modeltreat data as map
![Page 39: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/39.jpg)
Use finagle for service modulesplay is not for REST APIwhy pay the cost of HTTP?statisticsseparate REST and Data layermodularity
![Page 40: Tech Talk - Things I Learned at Scala Days 2013](https://reader034.vdocuments.mx/reader034/viewer/2022042815/55859acad8b42ad06d8b506e/html5/thumbnails/40.jpg)
Questions?