SlideShare a Scribd company logo
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 characterized by state, identity and
behavior - Grady Booch
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 it's important
Guideline #3
Prefer Functional
vals v.s. vars
recursions or combinators v.s. loops
immutable v.s. mutable collections
transformations v.s. CRUD*
Guideline #4
But, don't diabolize local state
sometimes, mutable gives better performance
sometimes, mutable adds convenience
vars v.s. vals
var interfaces = parseClassHeader()...
if (isAnnotation) interfaces += ClassFileAnnotation
val parsedIfaces = parseClassHeader()...
val interfaces =
if (isAnnotation) parsedIfaces + ClassFileAnnotation
else 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,
tdiscount + item.discount)
}
var totalPrice, totalDiscount = 0.0
for (item <- items) {
totalPrice += item.price
totalDiscount += item.discount
}
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 elegant solutions don't come to mind at the
first time
it is fun to find better solutions
Choice #1
Infix v.s. "."
Choice #2
Alphabetic v.s. Symbolic
val xs = List("apples", "oranges", "pears")
xs.foldLeft("")((result, i) => result + i)
("" /: xs)((result, i) => result + i)
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
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't nest too many levels
Choice #6
pattern matching v.s. dynamic
dispatch
the expression problem, check out
, lecture 4.5 and 4.6scala class @ coursera
Choice #7
type parameters v.s. abstract type
members
try type parameters first
avoid Animals[_]
a good article by Bill Venners
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 instead of hating Java
Any fool can write code that a computer can understand.
Good programmers write code that human can
understand.
- Martin Fowler
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
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
modularity
Questions?

More Related Content

PDF
Why Scala?
PDF
Short and fast introduction to Scala
PDF
Don't try these at home
KEY
ZIP
Why Scala for Web 2.0?
PPTX
OOP paradigm, principles of good design and architecture of Java applications
PDF
Java design patterns
PPTX
Introduction to Core Java Programming
Why Scala?
Short and fast introduction to Scala
Don't try these at home
Why Scala for Web 2.0?
OOP paradigm, principles of good design and architecture of Java applications
Java design patterns
Introduction to Core Java Programming

What's hot (20)

PPTX
Java
PPTX
PPTX
Introduction to Functional programming
PPT
00 intro to java
PPT
Workin ontherailsroad
PPT
WorkinOnTheRailsRoad
PPT
Introduction to java
PDF
Introduction to Scala
PDF
From delegates, to lamdas and expression trees your guide to elegant code in ...
PPTX
Coding Standard And Code Review
PPTX
Core java programming tutorial - Brainsmartlabs
PPTX
Presentation5
PPTX
02 java programming basic
PPSX
Spark in Action: analyzing big data with the Java API
PDF
EMPEX LA 2018 - Inclusion Starts with Docs
PPTX
Core java
PPTX
core java
PPT
Jug dynamic languages_in_jvm
PPT
Lambdas
PPTX
Comparing Golang and understanding Java Value Types
Java
Introduction to Functional programming
00 intro to java
Workin ontherailsroad
WorkinOnTheRailsRoad
Introduction to java
Introduction to Scala
From delegates, to lamdas and expression trees your guide to elegant code in ...
Coding Standard And Code Review
Core java programming tutorial - Brainsmartlabs
Presentation5
02 java programming basic
Spark in Action: analyzing big data with the Java API
EMPEX LA 2018 - Inclusion Starts with Docs
Core java
core java
Jug dynamic languages_in_jvm
Lambdas
Comparing Golang and understanding Java Value Types
Ad

Similar to Tech Talk - Things I Learned at Scala Days 2013 (20)

PPTX
ScalaDays 2013 Keynote Speech by Martin Odersky
PPTX
Scala - The Simple Parts, SFScala presentation
PPTX
An introduction to scala
RTF
Imp_Points_Scala
ODP
PDF
Scala Bay Meetup - The state of Scala code style and quality
PPTX
Scala for curious
PDF
Get Programming with Scala MEAP V05 Daniela Sfregola
PDF
Lecture1
PPT
Scala idioms
KEY
Learning from "Effective Scala"
PDF
Scala Intro
PPTX
Intro to Scala
PDF
Meet scala
ODP
Scala Presentation Work
PDF
Scala Quick Introduction
PDF
Programming in scala - 1
PDF
Ankara Jug - Practical Functional Programming with Scala
PPTX
Introduction to Scala
ODP
Functional programming with Scala
ScalaDays 2013 Keynote Speech by Martin Odersky
Scala - The Simple Parts, SFScala presentation
An introduction to scala
Imp_Points_Scala
Scala Bay Meetup - The state of Scala code style and quality
Scala for curious
Get Programming with Scala MEAP V05 Daniela Sfregola
Lecture1
Scala idioms
Learning from "Effective Scala"
Scala Intro
Intro to Scala
Meet scala
Scala Presentation Work
Scala Quick Introduction
Programming in scala - 1
Ankara Jug - Practical Functional Programming with Scala
Introduction to Scala
Functional programming with Scala
Ad

More from Hung Lin (6)

PDF
Handle TBs with $1500 per month
PDF
NE Scala 2016 roundup
PDF
6 Months Sailing with Docker in Production
PDF
Micro Services
PDF
Lunch_and_Learn_20150603
PDF
nescala 2013
Handle TBs with $1500 per month
NE Scala 2016 roundup
6 Months Sailing with Docker in Production
Micro Services
Lunch_and_Learn_20150603
nescala 2013

Recently uploaded (20)

PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
DOCX
search engine optimization ppt fir known well about this
PDF
Architecture types and enterprise applications.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Unlock new opportunities with location data.pdf
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
Five Habits of High-Impact Board Members
PDF
A novel scalable deep ensemble learning framework for big data classification...
O2C Customer Invoices to Receipt V15A.pptx
Getting started with AI Agents and Multi-Agent Systems
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
search engine optimization ppt fir known well about this
Architecture types and enterprise applications.pdf
1 - Historical Antecedents, Social Consideration.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Benefits of Physical activity for teenagers.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Zenith AI: Advanced Artificial Intelligence
Unlock new opportunities with location data.pdf
A review of recent deep learning applications in wood surface defect identifi...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
NewMind AI Weekly Chronicles – August ’25 Week III
Web Crawler for Trend Tracking Gen Z Insights.pptx
Five Habits of High-Impact Board Members
A novel scalable deep ensemble learning framework for big data classification...

Tech Talk - Things I Learned at Scala Days 2013