Scala in the Wild

Tomer Gabel
Tomer GabelConsulting Engineer at Substrate Software Services
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 (Java/JVM)
• Organizer of Scalapeño
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
SCALA IN A
NUTSHELL
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
Executive Summary
A better Java
• Less boilerplate
• Less baggage
• Less old and boring
• New toys to play with
• ⇒ Happier developers
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
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
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
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 libraries
– A single runtime
dependency!
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
MIGRATION STRATEGIES
1. Greenfield project
• Applicable for:
– New projects
– Self-contained
– Experimental/non-critical
• Assume 3-4 weeks’
overhead
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
}
}
}
3. The layered approach
Components
Frameworks
Deployment Executable Container
Crawler framework
Twitter TripAdvisor OpenTable
Web framework
Dashboard Backoffice
4. The silo approach
Components
Frameworks
Deployment Executable Container
Crawler framework
Twitter TripAdvisor OpenTable
Web framework
Dashboard Backoffice
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
01:26.4
01:43.7
02:01.0
02:18.2
02:35.5
02:52.8
Build #
Time
Initial Build
Refactoring
On Build Times
Developmen
t
• Use IDEA
• … or Eclipse
CI
• Using Maven?
Add Zinc
• … or use Sbt
Release
• Clean builds
• Skip Zinc
Embrace Immutability
• Scala makes it easy:
– “val” keyword
– Collections
– Case classes
• Do I need to reiterate why?
– Easier to reason about!
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.
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
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?
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!
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?
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.
Symbolic Operators
• Just because you can…
• … doesn’t mean you should
• What does that even mean?
s(7) <*> (s(8) <*> (s(9) ∘ add3))
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 documented
• Remember: YAGNI
A Word on Akka
• Akka is fantastic
– High performance
– Full-featured
– Great libraries (akka-http)
• But: is the actor model for you?
• Remember: YAGNI
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
1 of 44

More Related Content

What's hot(20)

Developing in the CloudDeveloping in the Cloud
Developing in the Cloud
Ryan Cuprak1.1K views
4 JVM Web Frameworks4 JVM Web Frameworks
4 JVM Web Frameworks
Joe Kutner686 views
Maven - Taming the BeastMaven - Taming the Beast
Maven - Taming the Beast
Roberto Cortez5.2K views
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
Johan Edstrom633 views
Scala profilingScala profiling
Scala profiling
Filippo Pacifici12.5K views
#JavaOne What's in an object?#JavaOne What's in an object?
#JavaOne What's in an object?
Charlie Gracie3.2K views
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
Tomer Gabel747 views
Scala in practiceScala in practice
Scala in practice
Tomer Gabel25.4K views
JavaOne 2015: 12 Factor AppJavaOne 2015: 12 Factor App
JavaOne 2015: 12 Factor App
Joe Kutner3.3K views
DevNexus 2019: Migrating to Java 11DevNexus 2019: Migrating to Java 11
DevNexus 2019: Migrating to Java 11
DaliaAboSheasha343 views
Stackato v6Stackato v6
Stackato v6
Jonas Brømsø1.2K views
Why akkaWhy akka
Why akka
Sapardi Sapardi578 views
Migrating to Java 11Migrating to Java 11
Migrating to Java 11
Arto Santala2.1K views
12-factor-jruby12-factor-jruby
12-factor-jruby
Joe Kutner818 views

Similar to Scala in the Wild(20)

The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne40.6K views
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
Roman Elizarov5.9K views
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open2.1K views
JS EssenceJS Essence
JS Essence
Uladzimir Piatryka2.2K views
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
Viplav Jain227 views
Parallel programmingParallel programming
Parallel programming
Swain Loda983 views
Scala IntroductionScala Introduction
Scala Introduction
Adrian Spender3.2K views
Java and the JVMJava and the JVM
Java and the JVM
Manish Pandit592 views
Google guava overviewGoogle guava overview
Google guava overview
Steve Min6.9K views
33rd degree33rd degree
33rd degree
Dariusz Kordonski347 views
Java ClosuresJava Closures
Java Closures
Ben Evans1.8K views
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
Vasil Remeniuk653 views
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
Vasil Remeniuk967 views
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai3.3K views
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & How
Graham Tackley2.9K views

More from Tomer Gabel(20)

Recently uploaded(20)

Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum120 views
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya59 views
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation24 views
ThroughputThroughput
Throughput
Moisés Armani Ramírez31 views
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman161 views

Scala in the Wild

  • 1. Scala in the Wild Tomer Gabel, JavaOne 2015
  • 2. Agenda • Scala in a nutshell • Bootstrapping • Practical Considerations • Ecosystem • Call to action
  • 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. 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
  • 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. Executive Summary A better Java • Less boilerplate • Less baggage • Less old and boring • New toys to play with • ⇒ Happier developers
  • 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. 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. 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
  • 12. Gimme Three Steps IntelliJ IDEA NetBeans Eclipse gradle maven ant 1. Stick with what you know
  • 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. 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
  • 16. 1. Greenfield project • Applicable for: – New projects – Self-contained – Experimental/non-critical • Assume 3-4 weeks’ overhead
  • 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. 3. The layered approach Components Frameworks Deployment Executable Container Crawler framework Twitter TripAdvisor OpenTable Web framework Dashboard Backoffice
  • 19. 4. The silo approach Components Frameworks Deployment Executable Container Crawler framework Twitter TripAdvisor OpenTable Web framework Dashboard Backoffice
  • 21. Books
  • 22. Online Resources Online training The usual suspects … and more
  • 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. On Build Times Developmen t • Use IDEA • … or Eclipse CI • Using Maven? Add Zinc • … or use Sbt Release • Clean builds • Skip Zinc
  • 26. Embrace Immutability • Scala makes it easy: – “val” keyword – Collections – Case classes • Do I need to reiterate why? – Easier to reason about!
  • 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. 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. 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. 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. 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. 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. Symbolic Operators • Just because you can… • … doesn’t mean you should • What does that even mean? s(7) <*> (s(8) <*> (s(9) ∘ add3))
  • 35. Let’s Get Busy • The Scala ecosystem is huge • It subsumes Java’s • Also features unique offerings • Let’s discuss a few…
  • 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. 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. Call to Action Last but not least…
  • 44. WE’RE DONE HERE! Time to push the green button :-) tomer@tomergabel.com @tomerg http://il.linkedin.com/in/tomergabel

Editor's Notes

  1. Image source: https://www.flickr.com/photos/sarairachel/7876010420 (CC)
  2. Image source: https://www.flickr.com/photos/60848944@N00/3537064556
  3. Image source: http://onlinesalesstepbystep.com/wp-content/uploads/2014/08/Toppling-books.jpg