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.
Scala Days 2013
by Hung Lin @hunglin
Scala the **** out of NYC
3 days event @ NYC
Scala Sunday @ meetup HQ: 8 talks
Shapeless workshop on Monday
Hot Topics
Scala 2.10
Style of Scala*
Asynchronous Programming - akka
Big Data / Streaming Data - Spark
Macro
Play
Keynote: Scala with Style
by Martin Odersky, creator of scala
What is OOP good for?
Fixed APIs with unknown implementations. e.g.
Simula67 for simulation, Smalltalk for GUI
Objects are...
OOP v.s. FP
Guideline #1
Keep it simple
Simple Made Easy - Rich Hichey
Guideline #2
Don't pack too much in one
expression
find meaningful names for the intermediate results. It's
not easy but i...
Guideline #3
Prefer Functional
vals v.s. vars
recursions or combinators v.s. loops
immutable v.s. mutable collections
tran...
Guideline #4
But, don't diabolize local state
sometimes, mutable gives better performance
sometimes, mutable adds convenie...
vars v.s. vals
var interfaces = parseClassHeader()...
if (isAnnotation) interfaces += ClassFileAnnotation
val parsedIfaces...
loops v.s. combinators
val totalPrice = items.map(_.price).sum
val totalDiscount = items.map(_.discount).sum
val (totalPrice, totalDiscount) =
items.foldLeft((0.0, 0.0)) {
case ((tprice, tdiscount), item) => (tprice + item.price,
t...
Guideline #5
Careful with mutable objects
val m = ArrayBuffer[Int]()
Guideline #6
Don't stop improving too early
shrink code by factor of 10 + make it more readable at
the same time
clean and...
Choice #1
Infix v.s. "."
Choice #2
Alphabetic v.s. Symbolic
val xs = List("apples", "oranges", "pears")
xs.foldLeft("")((result, i) => result + i)
...
Choice #3
Loop, recursion or combinators
try conbinators first
if it becomes too tedious, or efficiency is a big concern,
...
Choice #4
Procedures or "="
DON'T use procedure syntax
def method: Unit = {
// operations
}
Choice #5
Private v.s. nested
use nested function to avoid passing parameters
use nested function for small functions
don'...
Choice #6
pattern matching v.s. dynamic
dispatch
the expression problem, check out
, lecture 4.5 and 4.6scala class @ cour...
Choice #7
type parameters v.s. abstract type
members
try type parameters first
avoid Animals[_]
a good article by Bill Ven...
Keynote: Scala in 2018
by Rod Johnson, creator of Spring
in 2018
Java is still alive
Enterprise apps are using Scala
Startups are still NOT using Scala
myths / points
Readability over cleverness, LOC, FP, ...
Scala needs coding standard
Scala needs to move slower
Embracing ...
Any fool can write code that a computer can understand.
Good programmers write code that human can
understand.
- Martin Fo...
Debugging is twice as hard as writing the code in the first
place. Therefore, if you write the code as cleverly as
possibl...
Asynchronous Programming
asynchronous v.s. parallel
what else?
who's doing it?
asynchronous v.s. batching
pitfall: thread pool?
for tomcat, one thread handles one request
pitfall: back pressure
pitfall: performance v.s. scaling issue
pitfall: theory v.s. reality
cost of thread context switch
# of threads v.s. # of CPUs
where is the bottleneck?
Some thoughts about our system
Upgrade to scala 2.10
Use akka
asynchronous programming
fault tolerance
modular design
Use case class for data model
treat data as map
Use finagle for service modules
play is not for REST API
why pay the cost of HTTP?
statistics
separate REST and Data layer...
Questions?
Upcoming SlideShare
Loading in …5
×

Tech Talk - Things I Learned at Scala Days 2013

927 views

Published on

Tech Talk I gave at my company for the things I learned at Scala Days 2013

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Tech Talk - Things I Learned at Scala Days 2013

  1. 1. Scala Days 2013 by Hung Lin @hunglin
  2. 2. Scala the **** out of NYC 3 days event @ NYC Scala Sunday @ meetup HQ: 8 talks Shapeless workshop on Monday
  3. 3. Hot Topics Scala 2.10 Style of Scala* Asynchronous Programming - akka Big Data / Streaming Data - Spark Macro Play
  4. 4. Keynote: Scala with Style by Martin Odersky, creator of scala
  5. 5. What is OOP good for? Fixed APIs with unknown implementations. e.g. Simula67 for simulation, Smalltalk for GUI Objects are characterized by state, identity and behavior - Grady Booch
  6. 6. OOP v.s. FP
  7. 7. Guideline #1 Keep it simple Simple Made Easy - Rich Hichey
  8. 8. Guideline #2 Don't pack too much in one expression find meaningful names for the intermediate results. It's not easy but it's important
  9. 9. Guideline #3 Prefer Functional vals v.s. vars recursions or combinators v.s. loops immutable v.s. mutable collections transformations v.s. CRUD*
  10. 10. Guideline #4 But, don't diabolize local state sometimes, mutable gives better performance sometimes, mutable adds convenience
  11. 11. vars v.s. vals var interfaces = parseClassHeader()... if (isAnnotation) interfaces += ClassFileAnnotation val parsedIfaces = parseClassHeader()... val interfaces = if (isAnnotation) parsedIfaces + ClassFileAnnotation else parsedIfaces
  12. 12. loops v.s. combinators val totalPrice = items.map(_.price).sum val totalDiscount = items.map(_.discount).sum
  13. 13. val (totalPrice, totalDiscount) = items.foldLeft((0.0, 0.0)) { case ((tprice, tdiscount), item) => (tprice + item.price, tdiscount + item.discount) } var totalPrice, totalDiscount = 0.0 for (item <- items) { totalPrice += item.price totalDiscount += item.discount }
  14. 14. Guideline #5 Careful with mutable objects val m = ArrayBuffer[Int]()
  15. 15. Guideline #6 Don't stop improving too early shrink code by factor of 10 + make it more readable at the same time clean and elegant solutions don't come to mind at the first time it is fun to find better solutions
  16. 16. Choice #1 Infix v.s. "."
  17. 17. Choice #2 Alphabetic v.s. Symbolic val xs = List("apples", "oranges", "pears") xs.foldLeft("")((result, i) => result + i) ("" /: xs)((result, i) => result + i)
  18. 18. Choice #3 Loop, recursion or combinators try conbinators first if it becomes too tedious, or efficiency is a big concern, try tail-recursion use loop for simple case or for readability
  19. 19. Choice #4 Procedures or "=" DON'T use procedure syntax def method: Unit = { // operations }
  20. 20. Choice #5 Private v.s. nested use nested function to avoid passing parameters use nested function for small functions don't nest too many levels
  21. 21. Choice #6 pattern matching v.s. dynamic dispatch the expression problem, check out , lecture 4.5 and 4.6scala class @ coursera
  22. 22. Choice #7 type parameters v.s. abstract type members try type parameters first avoid Animals[_] a good article by Bill Venners
  23. 23. Keynote: Scala in 2018 by Rod Johnson, creator of Spring
  24. 24. in 2018 Java is still alive Enterprise apps are using Scala Startups are still NOT using Scala
  25. 25. myths / points Readability over cleverness, LOC, FP, ... Scala needs coding standard Scala needs to move slower Embracing instead of hating Java
  26. 26. Any fool can write code that a computer can understand. Good programmers write code that human can understand. - Martin Fowler
  27. 27. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. - Brian Kernighan
  28. 28. Asynchronous Programming
  29. 29. asynchronous v.s. parallel what else? who's doing it?
  30. 30. asynchronous v.s. batching
  31. 31. pitfall: thread pool? for tomcat, one thread handles one request
  32. 32. pitfall: back pressure
  33. 33. pitfall: performance v.s. scaling issue
  34. 34. pitfall: theory v.s. reality cost of thread context switch # of threads v.s. # of CPUs where is the bottleneck?
  35. 35. Some thoughts about our system
  36. 36. Upgrade to scala 2.10
  37. 37. Use akka asynchronous programming fault tolerance modular design
  38. 38. Use case class for data model treat data as map
  39. 39. Use finagle for service modules play is not for REST API why pay the cost of HTTP? statistics separate REST and Data layer modularity
  40. 40. Questions?

×