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 in the Wild
Tomer Gabel, JavaOne 2015
Agenda
• Scala in a nutshell
• Bootstrapping
• Practical
Considerations
• Ecosystem
• Call to action
Who is this guy?
Me
• System architect at Wix
• Scala user since 2011
• User group leader:
– Underscore (Scala)
– Java.IL ...
Who is this guy?
Me
• System architect at Wix
• Scala user since 2011
• User group leader:
– Underscore (Scala)
– Java.IL ...
SCALA IN A
NUTSHELL
Recap
• You’ve heard it all before!
– Statically-typed
– Targets the JVM
– … and JavaScript, and Android
– Hybrid object-o...
Executive Summary
A better Java
• Less boilerplate
• Less baggage
• Less old and boring
• New toys to play with
• ⇒ Happie...
Executive Summary
A better Java
• Less boilerplate
• Less baggage
• Less old and boring
• New toys to play with
• ⇒ Happie...
Executive Summary
A better Java
• Less boilerplate
• Less baggage
• Less old and boring
Gateway drug to
Haskell
• Can be f...
The Fineprint
• Warts
– Compilation times
– Imperfect IDEs
– Documentation
– Debugging*
• Semi-known quantity
– Still pret...
Bootstrapping
Gimme Three Steps
IntelliJ IDEA
NetBeans
Eclipse
gradle
maven
ant
1. Stick with what you know
Gimme Three Steps
Hibernate
Guava/Guice
Spring
2. Grow a hybrid codebase
• Mix Scala/Java freely!
– Same codebase
– Same l...
Gimme Three Steps
3. Keep it simple
• You don’t have to go all in
• In fact, you probably shouldn’t:
– Language mastery ta...
MIGRATION STRATEGIES
1. Greenfield project
• Applicable for:
– New projects
– Self-contained
– Experimental/non-critical
• Assume 3-4 weeks’
ov...
2. Gateway drug
• Scala rocks your tests!
– Expressive syntax
– DSL support
– Excellent libraries
• Trivial integration
– ...
3. The layered approach
Components
Frameworks
Deployment Executable Container
Crawler framework
Twitter TripAdvisor OpenTa...
4. The silo approach
Components
Frameworks
Deployment Executable Container
Crawler framework
Twitter TripAdvisor OpenTable...
Learnin
g
Books
Online Resources
Online training The usual suspects
… and more
PRACTICAL
CONSIDERATIONS
On Build Times
• Compiling Scala
is slow…
• Incremental
compilation helps. A
lot 00:00.0
00:17.3
00:34.6
00:51.8
01:09.1
0...
On Build Times
Developmen
t
• Use IDEA
• … or Eclipse
CI
• Using Maven?
Add Zinc
• … or use Sbt
Release
• Clean builds
• S...
Embrace Immutability
• Scala makes it easy:
– “val” keyword
– Collections
– Case classes
• Do I need to reiterate why?
– E...
Functional Madness
• Scala supports functional programming
• That doesn’t mean you do…
– Recursion is hard
– Category theo...
Collective Abuse
• Scala has a massive
collection library
• Loads of built-ins too
– Case classes
– Functions and partials...
Collective Abuse
• Anti-pattern: Too many inline steps
val actors: List[(Int, String, Double)] = // ...
def bestActor(quer...
Collective Abuse
• Anti-pattern: Too many inline steps
val actors: List[(Int, String, Double)] = // ...
def bestActor(quer...
Collective Abuse
• Anti-pattern: Tuple overload
val actors: List[(Int, String, Double)] = // ...
def bestActor(query: Stri...
Collective Abuse
• Anti-pattern: Tuple overload
case class Actor(id: Int, name: String, score: Double)
def bestActor(query...
Symbolic Operators
• Just because you can…
• … doesn’t mean you should
• What does that even mean?
s(7) <*> (s(8) <*> (s(9...
Ecosystem
Let’s Get Busy
• The Scala ecosystem is huge
• It subsumes Java’s
• Also features unique offerings
• Let’s discuss a few…
Testing
Web Servers
Microservices
Cautionary Tale
• Beware scalaz and cats
– Both are amazing
– Both do a lot
– But they’re quite advanced
– … and poorly do...
A Word on Akka
• Akka is fantastic
– High performance
– Full-featured
– Great libraries (akka-http)
• But: is the actor mo...
Call to
Action
Last but not least…
>120 User Groups
worldwide!
http://scala.space
Participate!
Participate!
WE’RE DONE HERE!
Time to push the green button :-)
tomer@tomergabel.com
@tomerg
http://il.linkedin.com/in/tomergabel
Upcoming SlideShare
Loading in …5
×

Scala in the Wild

2,448 views

Published on

The Scala programming language has been gaining significant traction over the last few years, being adopted by vastly different organizations from startups to large enterprises. While the language itself is pretty well understood and explained in tutorials and books, there is an apparent dearth of practical advice for new adopters on the best approach to integrating the new technology. In this talk I’ll attempt to offer such advice gathered over several years of production Scala use, focusing on tools, practices, patterns and the community, in the hope of making your transition into the Scala ecosystem easier and better-informed up front.

A talk given at JavaOne 2015 in San Francisco.

Published in: Technology
  • Be the first to comment

Scala in the Wild

  1. 1. Scala in the Wild Tomer Gabel, JavaOne 2015
  2. 2. Agenda • Scala in a nutshell • Bootstrapping • Practical Considerations • Ecosystem • Call to action
  3. 3. Who is this guy? Me • System architect at Wix • Scala user since 2011 • User group leader: – Underscore (Scala) – Java.IL (Java/JVM) • Organizer of Scalapeño
  4. 4. Who is this guy? Me • System architect at Wix • Scala user since 2011 • User group leader: – Underscore (Scala) – Java.IL (Java/JVM) • Organizer of Scalapeño Wix • >70M sites • Scala shop since 2012 • The usual suspects: – Microservices – Continuous delivery – Legacy Java codebase
  5. 5. SCALA IN A NUTSHELL
  6. 6. Recap • You’ve heard it all before! – Statically-typed – Targets the JVM – … and JavaScript, and Android – Hybrid object-oriented/functional – Ponies, unicorns, yada yada yada
  7. 7. Executive Summary A better Java • Less boilerplate • Less baggage • Less old and boring • New toys to play with • ⇒ Happier developers
  8. 8. Executive Summary A better Java • Less boilerplate • Less baggage • Less old and boring • New toys to play with • ⇒ Happier developers Gateway drug to Haskell • Can be functional • ... if you want it to • Better abstractions
  9. 9. Executive Summary A better Java • Less boilerplate • Less baggage • Less old and boring Gateway drug to Haskell • Can be functional • ... if you want it to • Better abstractions • New toys to play with • ⇒ Happier developers
  10. 10. The Fineprint • Warts – Compilation times – Imperfect IDEs – Documentation – Debugging* • Semi-known quantity – Still pretty new – Few best practices – No style guide – New ⇒ prone to abuse
  11. 11. Bootstrapping
  12. 12. Gimme Three Steps IntelliJ IDEA NetBeans Eclipse gradle maven ant 1. Stick with what you know
  13. 13. Gimme Three Steps Hibernate Guava/Guice Spring 2. Grow a hybrid codebase • Mix Scala/Java freely! – Same codebase – Same libraries – A single runtime dependency!
  14. 14. Gimme Three Steps 3. Keep it simple • You don’t have to go all in • In fact, you probably shouldn’t: – Language mastery takes time – Paradigm shifts take time • Start slowly and learn as you go
  15. 15. MIGRATION STRATEGIES
  16. 16. 1. Greenfield project • Applicable for: – New projects – Self-contained – Experimental/non-critical • Assume 3-4 weeks’ overhead
  17. 17. 2. Gateway drug • Scala rocks your tests! – Expressive syntax – DSL support – Excellent libraries • Trivial integration – Ant/Maven/Gradle… – Non-production code! class StackTest extends Specification { "Seq.head" should { "throw an exception if empty" in { Seq.empty[Any].head should throwA[NoSuchElementException] } "return the first element" in { Seq(1, 2, 3).head shouldEqual 1 } } }
  18. 18. 3. The layered approach Components Frameworks Deployment Executable Container Crawler framework Twitter TripAdvisor OpenTable Web framework Dashboard Backoffice
  19. 19. 4. The silo approach Components Frameworks Deployment Executable Container Crawler framework Twitter TripAdvisor OpenTable Web framework Dashboard Backoffice
  20. 20. Learnin g
  21. 21. Books
  22. 22. Online Resources Online training The usual suspects … and more
  23. 23. PRACTICAL CONSIDERATIONS
  24. 24. On Build Times • Compiling Scala is slow… • Incremental compilation helps. A lot 00:00.0 00:17.3 00:34.6 00:51.8 01:09.1 01:26.4 01:43.7 02:01.0 02:18.2 02:35.5 02:52.8 Build # Time Initial Build Refactoring
  25. 25. On Build Times Developmen t • Use IDEA • … or Eclipse CI • Using Maven? Add Zinc • … or use Sbt Release • Clean builds • Skip Zinc
  26. 26. Embrace Immutability • Scala makes it easy: – “val” keyword – Collections – Case classes • Do I need to reiterate why? – Easier to reason about!
  27. 27. Functional Madness • Scala supports functional programming • That doesn’t mean you do… – Recursion is hard – Category theory is hard – Being side-effect free is hard • Stick to what you know… for now.
  28. 28. Collective Abuse • Scala has a massive collection library • Loads of built-ins too – Case classes – Functions and partials – Tuples, tuples, tuples • Fairly easy to abuse
  29. 29. Collective Abuse • Anti-pattern: Too many inline steps val actors: List[(Int, String, Double)] = // ... def bestActor(query: String) = actors.filter(_._2 contains query) .sortBy(-_._3) .map(_._1) .headOption 1. What does this even do?! 2. How does data flow here?
  30. 30. Collective Abuse • Anti-pattern: Too many inline steps val actors: List[(Int, String, Double)] = // ... def bestActor(query: String) = { val matching = actors.filter(_._2 contains query) val bestByScore = matching.sortBy(-_._3).headOption bestByScore.map(_._1) } Name intermediate steps!
  31. 31. Collective Abuse • Anti-pattern: Tuple overload val actors: List[(Int, String, Double)] = // ... def bestActor(query: String) = actors.filter(_._2 contains query) .sortBy(-_._3) .map(_._1) .headOption What’s with all these underscores?
  32. 32. Collective Abuse • Anti-pattern: Tuple overload case class Actor(id: Int, name: String, score: Double) def bestActor(query: String, actors: List[Actor]) = actors.filter(_.name contains query) .sortBy(-_.score) .map(_.id) .headOption Scala classes are cheap. Use them.
  33. 33. Symbolic Operators • Just because you can… • … doesn’t mean you should • What does that even mean? s(7) <*> (s(8) <*> (s(9) ∘ add3))
  34. 34. Ecosystem
  35. 35. Let’s Get Busy • The Scala ecosystem is huge • It subsumes Java’s • Also features unique offerings • Let’s discuss a few…
  36. 36. Testing
  37. 37. Web Servers
  38. 38. Microservices
  39. 39. Cautionary Tale • Beware scalaz and cats – Both are amazing – Both do a lot – But they’re quite advanced – … and poorly documented • Remember: YAGNI
  40. 40. A Word on Akka • Akka is fantastic – High performance – Full-featured – Great libraries (akka-http) • But: is the actor model for you? • Remember: YAGNI
  41. 41. Call to Action Last but not least…
  42. 42. >120 User Groups worldwide! http://scala.space Participate!
  43. 43. Participate!
  44. 44. WE’RE DONE HERE! Time to push the green button :-) tomer@tomergabel.com @tomerg http://il.linkedin.com/in/tomergabel

×