Scala in practice

Tomer Gabel
Tomer GabelConsulting Engineer um Substrate Software Services
Scala In Practice:
    A Case Study
Tomer Gabel, newBrandAnalytics
                    April 2012
Scala in practice
Some context


                               circa 2011:

• Startup with limited budget
• Cloud hosted, Linux based
• Complex prototype codebase
  – Lots of Java code
  – Serving paying customers
Strategy 101




                         Supplant
 Evolve     Refactor                   Complete
                         with new
codebase   and extend                   rewrite
                        architecture
Data points


• Complete system rewrite impractical
  – Too much code
  – Business continuity a priority
  – Cannot afford product stagnation
• Team comfortable with Java platform
• … but want a better language
Why Scala?



• JVM-targeted, statically typed
• Success stories (Twitter, Foursquare,
  LinkedIn)
• Active community
• Good (not perfect) tool ecosystem
• Reasonable learning curve
Alternatives

               • Dynamic
               • LISP dialect


               • Dynamic
               • Java-like syntax
               • Script-oriented

               • Static
               • Java-like syntax
               • In its infancy
Scala in a nutshell


• Pervasive type inference
Scala in a nutshell


• Type aliases, closures, first class functions
  and comprehensions                        Output:
Scala in a nutshell


• Imperative with functional-style
  constructs
Scala in a nutshell


• Traits: static mixins
Scala in a nutshell


• Pattern matching FTW!
Scala in a nutshell


• Other goodies
  –   Option wrappers (no more NPEs!)
  –   Powerful collection framework
  –   Implicit conversions
  –   Concurrent, immutable maps (HAMT)
  –   Built in actors
Scala in practice
Caveat emptor


• Scala is bleeding edge
• You will get cut
  – Learning curve
  – Rough edges
  – Partial/outdated documentation
• It’s well worth it, if you’re prepared!
Focal points


• Learning curve
• Tooling
• In production
Learning curve


• Risks:
  – Functional constructs need getting used
    to
  – Few best practices:
     • Coding conventions
     • Patterns
     • “Dangerous” features
Learning curve


• Mitigations:
  – Relatively familiar syntax
  – Seamless Java integration
     • Evolve your codebase to include Scala
     • Reuse existing components and libraries
  – Lots of wow moments!
Lessons learned


“New techniques are easy to explain.
Old techniques are hard to maintain.”
             - an old Vulcan proverb

• Encourage experimentation
• Encourage rapid iteration
• Document and share new techniques
Lessons learned


• Get a good grasp of the basics:
  –   Functions and closures
  –   Option wrappers
  –   Pattern matching
  –   Traits, traits and traits
• Each of these is immensely powerful
• Together, they make ponies!
Lessons learned


• Avoid wacky syntax!
  – Some common Scala libraries have
    atrocious syntax (scalaz)
  – Does this make sense to you?
  val p2c = ((_: Int) * (_: Int)).curried
  some(5) <*> (some(3) <*> p2c.pure[Option]) should
  equal(Some(15))
Lessons learned


• Promote functional constructs:
  – Intent over implementation
  – Massive code savings
  – Immutability, correct code by
   design
• Mentor junior developers!
Lessons learned


• Don’t go overboard
  – Use implicits sparingly
  – Avoid tuple overload
    • x._1._2 * x._2 orElse x._3 == yuck
    • Use case classes and partial functions
      instead
  – Path-dependent types are scary!
Focal points


• Learning curve
• Tooling
• In production
IDE Support


• Eclipse support via TypeSafe’s own
  ScalaIDE
• IntelliJ IDEA support via plugin
IDE support


•   Lower your expectations
•   Don’t skimp on dev hardware!
•   Use latest IDE/plugin builds
•   Take your time
    – Grok the tool-chain
    – Assign a “go-to guy” (or gal)
IDE support


• Wonky debugging
  – Java debuggers work…
  – … with some caveats
    • Step into synthetic stack frames
    • Do not step over closures
  – TypeSafe are focusing on debugging
  – JetBrains will likely follow
IDE support


• Except the unexpected
  – Spurious error highlighting
    • Especially with implicit conversions
    • Double-check with your build tool-
      chain
  – Rebuild the project occasionally
  – The situation is improving daily
Build tools


• Native Scala build tool is sbt
  – Ivy2 (-> Maven repositories)
  – Scala syntax
  – Very powerful, sharp learning curve
• Stay away from ant
• Maven and buildr should work fine
Library ecosystem


• Surprisingly mature landscape!
• We use:
  – ScalaTest + ScalaMock
  – Squeryl
  – Scalatra
• Use your favorite Java libraries
  natively!
Focal points


• Learning curve
• Tooling
• In production
GC considerations


• Lots of generated classes
  – Higher PermGen utilization
  – Increase -XX:MaxPermSize


• Lots of intermediate objects
  – High eden space churn (normally OK)
  – Tune with –XX:NewRatio
Other considerations


• Scalac emits lots of synthetic
  code
  – Deep call graph
  – Intermediate stack frames
• Default stack often too small
  – -Xss=2m should do
Nasty surprises


• Different compiler, different edge-
  cases
  – Stack overflow may segfault
  – Crash log may fail to generate (JDK
    1.6.0_x)
  – Logs and thread dumps are your friends
Scala in practice
Codebase evolution

 Import Java
  codebase             Refactoring




                                        Tipping point


                          Slow growth
       Initial Scala
     experimentation
Conclusion


• I would recommend Scala for:
   – Startups willing to take the plunge
   – Small teams of senior developers
   – Large enterprises with tech advisory/leadership
     teams
• But not (yet) for:
   – Contractors
   – Traditional enterprises
Questions?
… answers may be forthcoming
Afterword


• newBrandAnalytics for allowing the use of
  the company name and R&D evidence
• TypeSafe and the amazing Scala
  community for making Scala what it is
• … and SmileTemplate.com for the
  PowerPoint template
• Get in touch!
  – tomer@tomergabel.com
  – http://www.tomergabel.com
Scala in practice
Scala in practice
1 von 41

Recomendados

Scala profiling von
Scala profilingScala profiling
Scala profilingFilippo Pacifici
12.5K views36 Folien
Java 8 and Beyond, a Scala Story von
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryTomer Gabel
747 views24 Folien
Scala, Akka, and Play: An Introduction on Heroku von
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
16.8K views51 Folien
Using Scala for building DSLs von
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
8.6K views26 Folien
Writing DSL's in Scala von
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in ScalaAbhijit Sharma
10.8K views33 Folien
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう! von
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
3.2K views58 Folien

Más contenido relacionado

Was ist angesagt?

Scala for C# Developers von
Scala for C# DevelopersScala for C# Developers
Scala for C# DevelopersOmer van Kloeten
7.4K views29 Folien
Scala Days NYC 2016 von
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016Martin Odersky
74.2K views63 Folien
An Introduction to Scala von
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
1.7K views25 Folien
Composable Futures with Akka 2.0 von
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Mike Slinn
4.5K views41 Folien
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab von
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
240 views67 Folien
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo von
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoTaro L. Saito
3K views37 Folien

Was ist angesagt?(20)

An Introduction to Scala von Brent Lemons
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
Brent Lemons1.7K views
Composable Futures with Akka 2.0 von Mike Slinn
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
Mike Slinn4.5K views
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab von CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab240 views
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo von Taro L. Saito
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Taro L. Saito3K views
Scala adoption by enterprises von Mike Slinn
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
Mike Slinn8K views
Why Scala Is Taking Over the Big Data World von Dean Wampler
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data World
Dean Wampler41.7K views
Machine learning with Apache Spark MLlib | Big Data Hadoop Spark Tutorial | C... von CloudxLab
Machine learning with Apache Spark MLlib | Big Data Hadoop Spark Tutorial | C...Machine learning with Apache Spark MLlib | Big Data Hadoop Spark Tutorial | C...
Machine learning with Apache Spark MLlib | Big Data Hadoop Spark Tutorial | C...
CloudxLab555 views
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ... von scalaconfjp
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
scalaconfjp3.3K views
Neo4 + Grails von stasimus
Neo4 + GrailsNeo4 + Grails
Neo4 + Grails
stasimus1.1K views
Concurrency Constructs Overview von stasimus
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
stasimus1.6K views
Scala in the Wild von Tomer Gabel
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel2.8K views
Speaking Scala: Refactoring for Fun and Profit (Workshop) von Tomer Gabel
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Tomer Gabel765 views
Sbt, idea and eclipse von Mike Slinn
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
Mike Slinn1.4K views
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介 von scalaconfjp
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
scalaconfjp2.5K views
Java Serialization Facts and Fallacies von Roman Elizarov
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
Roman Elizarov5.9K views

Destacado

Scala Talk at FOSDEM 2009 von
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
37.2K views42 Folien
Scala test von
Scala testScala test
Scala testInphina Technologies
4.7K views20 Folien
Metaprogramming in Scala 2.10, Eugene Burmako, von
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
5.3K views41 Folien
Scalding: Twitter's Scala DSL for Hadoop/Cascading von
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascadingjohnynek
10.4K views34 Folien
Scala Back to Basics: Type Classes von
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
3.7K views35 Folien
Procedure Typing for Scala von
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
6.7K views79 Folien

Destacado(20)

Scala Talk at FOSDEM 2009 von Martin Odersky
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky37.2K views
Metaprogramming in Scala 2.10, Eugene Burmako, von Vasil Remeniuk
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
Vasil Remeniuk5.3K views
Scalding: Twitter's Scala DSL for Hadoop/Cascading von johnynek
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
johnynek10.4K views
Scala Back to Basics: Type Classes von Tomer Gabel
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel3.7K views
Procedure Typing for Scala von akuklev
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
akuklev6.7K views
5 Bullets to Scala Adoption von Tomer Gabel
5 Bullets to Scala Adoption5 Bullets to Scala Adoption
5 Bullets to Scala Adoption
Tomer Gabel2.7K views
How shit works: the CPU von Tomer Gabel
How shit works: the CPUHow shit works: the CPU
How shit works: the CPU
Tomer Gabel1.8K views
Scala von popeast
ScalaScala
Scala
popeast999 views
Infinum Android Talks #20 - Benefits of using Kotlin von Infinum
Infinum Android Talks #20 - Benefits of using KotlinInfinum Android Talks #20 - Benefits of using Kotlin
Infinum Android Talks #20 - Benefits of using Kotlin
Infinum297 views
Do Languages Matter? von Bruce Eckel
Do Languages Matter?Do Languages Matter?
Do Languages Matter?
Bruce Eckel2.2K views
Kotlin в production. Как и зачем? von DotNetConf
Kotlin в production. Как и зачем?Kotlin в production. Как и зачем?
Kotlin в production. Как и зачем?
DotNetConf1.4K views
Programming in scala - 1 von Mukesh Kumar
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
Mukesh Kumar3.9K views
Kotlin advanced - language reference for android developers von Bartosz Kosarzycki
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki5.7K views

Similar a Scala in practice

Introducing Scala to your Ruby/Java Shop : My experiences at IGN von
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
1.5K views35 Folien
From java to scala at crowd mix von
From java to scala at crowd mixFrom java to scala at crowd mix
From java to scala at crowd mixStefano Galarraga
736 views19 Folien
Clojure in real life 17.10.2014 von
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
3.6K views62 Folien
Evolving IGN’s New APIs with Scala von
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with ScalaManish Pandit
1.1K views33 Folien
Polyglot Plugin Programming von
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
1.1K views95 Folien
Scala and Spark are Ideal for Big Data von
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataJohn Nestor
350 views15 Folien

Similar a Scala in practice(20)

Introducing Scala to your Ruby/Java Shop : My experiences at IGN von Manish Pandit
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit1.5K views
Clojure in real life 17.10.2014 von Metosin Oy
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
Metosin Oy3.6K views
Evolving IGN’s New APIs with Scala von Manish Pandit
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
Manish Pandit1.1K views
Polyglot Plugin Programming von Atlassian
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian1.1K views
Scala and Spark are Ideal for Big Data von John Nestor
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big Data
John Nestor350 views
Polyglot and Functional Programming (OSCON 2012) von Martijn Verburg
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg2.7K views
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle von Domino Data Lab
Scala and Spark are Ideal for Big Data - Data Science Pop-up SeattleScala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
Domino Data Lab 5.1K views
Code reviews von Roger Xia
Code reviewsCode reviews
Code reviews
Roger Xia606 views
Polyglot and functional (Devoxx Nov/2011) von Martijn Verburg
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg885 views
Modern Java Concurrency (OSCON 2012) von Martijn Verburg
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
Martijn Verburg4.2K views
Java Closures von Ben Evans
Java ClosuresJava Closures
Java Closures
Ben Evans1.8K views
Spark - The Ultimate Scala Collections by Martin Odersky von Spark Summit
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
Spark Summit5.7K views
A Tour Of Scala von fanf42
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
fanf423.4K views
Scala & Spark Online Training von Learntek1
Scala & Spark Online TrainingScala & Spark Online Training
Scala & Spark Online Training
Learntek146 views
Experience Converting from Ruby to Scala von John Nestor
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
John Nestor1K views

Más de Tomer Gabel

How shit works: Time von
How shit works: TimeHow shit works: Time
How shit works: TimeTomer Gabel
342 views53 Folien
Nondeterministic Software for the Rest of Us von
Nondeterministic Software for the Rest of UsNondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of UsTomer Gabel
329 views39 Folien
Slaying Sacred Cows: Deconstructing Dependency Injection von
Slaying Sacred Cows: Deconstructing Dependency InjectionSlaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency InjectionTomer Gabel
1.3K views34 Folien
An Abridged Guide to Event Sourcing von
An Abridged Guide to Event SourcingAn Abridged Guide to Event Sourcing
An Abridged Guide to Event SourcingTomer Gabel
1K views32 Folien
How Shit Works: Storage von
How Shit Works: StorageHow Shit Works: Storage
How Shit Works: StorageTomer Gabel
914 views44 Folien
The Wix Microservice Stack von
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice StackTomer Gabel
1.7K views42 Folien

Más de Tomer Gabel(20)

How shit works: Time von Tomer Gabel
How shit works: TimeHow shit works: Time
How shit works: Time
Tomer Gabel342 views
Nondeterministic Software for the Rest of Us von Tomer Gabel
Nondeterministic Software for the Rest of UsNondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of Us
Tomer Gabel329 views
Slaying Sacred Cows: Deconstructing Dependency Injection von Tomer Gabel
Slaying Sacred Cows: Deconstructing Dependency InjectionSlaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency Injection
Tomer Gabel1.3K views
An Abridged Guide to Event Sourcing von Tomer Gabel
An Abridged Guide to Event SourcingAn Abridged Guide to Event Sourcing
An Abridged Guide to Event Sourcing
Tomer Gabel1K views
How Shit Works: Storage von Tomer Gabel
How Shit Works: StorageHow Shit Works: Storage
How Shit Works: Storage
Tomer Gabel914 views
The Wix Microservice Stack von Tomer Gabel
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice Stack
Tomer Gabel1.7K views
Scala Refactoring for Fun and Profit (Japanese subtitles) von Tomer Gabel
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)
Tomer Gabel6.6K views
Scala Refactoring for Fun and Profit von Tomer Gabel
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
Tomer Gabel985 views
Onboarding at Scale von Tomer Gabel
Onboarding at ScaleOnboarding at Scale
Onboarding at Scale
Tomer Gabel1.5K views
Put Your Thinking CAP On von Tomer Gabel
Put Your Thinking CAP OnPut Your Thinking CAP On
Put Your Thinking CAP On
Tomer Gabel3.5K views
Leveraging Scala Macros for Better Validation von Tomer Gabel
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better Validation
Tomer Gabel1.4K views
A Field Guide to DSL Design in Scala von Tomer Gabel
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
Tomer Gabel6.5K views
Functional Leap of Faith (Keynote at JDay Lviv 2014) von Tomer Gabel
Functional Leap of Faith (Keynote at JDay Lviv 2014)Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Tomer Gabel1.5K views
Nashorn: JavaScript that doesn’t suck (ILJUG) von Tomer Gabel
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
Tomer Gabel5.9K views
Ponies and Unicorns With Scala von Tomer Gabel
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
Tomer Gabel962 views
Lab: JVM Production Debugging 101 von Tomer Gabel
Lab: JVM Production Debugging 101Lab: JVM Production Debugging 101
Lab: JVM Production Debugging 101
Tomer Gabel2.1K views
DevCon³: Scala Best Practices von Tomer Gabel
DevCon³: Scala Best PracticesDevCon³: Scala Best Practices
DevCon³: Scala Best Practices
Tomer Gabel3.7K views
Maven for Dummies von Tomer Gabel
Maven for DummiesMaven for Dummies
Maven for Dummies
Tomer Gabel6.3K views
SHC Israel: GigaSpaces Case Study von Tomer Gabel
SHC Israel: GigaSpaces Case StudySHC Israel: GigaSpaces Case Study
SHC Israel: GigaSpaces Case Study
Tomer Gabel734 views
The Demoscene: A cursory introduction von Tomer Gabel
The Demoscene: A cursory introductionThe Demoscene: A cursory introduction
The Demoscene: A cursory introduction
Tomer Gabel589 views

Último

Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... von
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...ShapeBlue
173 views15 Folien
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue von
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
138 views15 Folien
State of the Union - Rohit Yadav - Apache CloudStack von
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStackShapeBlue
297 views53 Folien
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue von
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
222 views7 Folien
Business Analyst Series 2023 - Week 4 Session 7 von
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
139 views31 Folien
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... von
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...ShapeBlue
106 views12 Folien

Último(20)

Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... von ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue173 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue von ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue138 views
State of the Union - Rohit Yadav - Apache CloudStack von ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue297 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue von ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue222 views
Business Analyst Series 2023 - Week 4 Session 7 von DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10139 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... von ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue106 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool von ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue123 views
"Surviving highload with Node.js", Andrii Shumada von Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays56 views
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... von ShapeBlue
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
ShapeBlue132 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... von ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue119 views
NTGapps NTG LowCode Platform von Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu423 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... von ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue180 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs von Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash158 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... von Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker54 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems von ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue238 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... von ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue194 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... von James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson160 views

Scala in practice

  • 1. Scala In Practice: A Case Study Tomer Gabel, newBrandAnalytics April 2012
  • 3. Some context circa 2011: • Startup with limited budget • Cloud hosted, Linux based • Complex prototype codebase – Lots of Java code – Serving paying customers
  • 4. Strategy 101 Supplant Evolve Refactor Complete with new codebase and extend rewrite architecture
  • 5. Data points • Complete system rewrite impractical – Too much code – Business continuity a priority – Cannot afford product stagnation • Team comfortable with Java platform • … but want a better language
  • 6. Why Scala? • JVM-targeted, statically typed • Success stories (Twitter, Foursquare, LinkedIn) • Active community • Good (not perfect) tool ecosystem • Reasonable learning curve
  • 7. Alternatives • Dynamic • LISP dialect • Dynamic • Java-like syntax • Script-oriented • Static • Java-like syntax • In its infancy
  • 8. Scala in a nutshell • Pervasive type inference
  • 9. Scala in a nutshell • Type aliases, closures, first class functions and comprehensions Output:
  • 10. Scala in a nutshell • Imperative with functional-style constructs
  • 11. Scala in a nutshell • Traits: static mixins
  • 12. Scala in a nutshell • Pattern matching FTW!
  • 13. Scala in a nutshell • Other goodies – Option wrappers (no more NPEs!) – Powerful collection framework – Implicit conversions – Concurrent, immutable maps (HAMT) – Built in actors
  • 15. Caveat emptor • Scala is bleeding edge • You will get cut – Learning curve – Rough edges – Partial/outdated documentation • It’s well worth it, if you’re prepared!
  • 16. Focal points • Learning curve • Tooling • In production
  • 17. Learning curve • Risks: – Functional constructs need getting used to – Few best practices: • Coding conventions • Patterns • “Dangerous” features
  • 18. Learning curve • Mitigations: – Relatively familiar syntax – Seamless Java integration • Evolve your codebase to include Scala • Reuse existing components and libraries – Lots of wow moments!
  • 19. Lessons learned “New techniques are easy to explain. Old techniques are hard to maintain.” - an old Vulcan proverb • Encourage experimentation • Encourage rapid iteration • Document and share new techniques
  • 20. Lessons learned • Get a good grasp of the basics: – Functions and closures – Option wrappers – Pattern matching – Traits, traits and traits • Each of these is immensely powerful • Together, they make ponies!
  • 21. Lessons learned • Avoid wacky syntax! – Some common Scala libraries have atrocious syntax (scalaz) – Does this make sense to you? val p2c = ((_: Int) * (_: Int)).curried some(5) <*> (some(3) <*> p2c.pure[Option]) should equal(Some(15))
  • 22. Lessons learned • Promote functional constructs: – Intent over implementation – Massive code savings – Immutability, correct code by design • Mentor junior developers!
  • 23. Lessons learned • Don’t go overboard – Use implicits sparingly – Avoid tuple overload • x._1._2 * x._2 orElse x._3 == yuck • Use case classes and partial functions instead – Path-dependent types are scary!
  • 24. Focal points • Learning curve • Tooling • In production
  • 25. IDE Support • Eclipse support via TypeSafe’s own ScalaIDE • IntelliJ IDEA support via plugin
  • 26. IDE support • Lower your expectations • Don’t skimp on dev hardware! • Use latest IDE/plugin builds • Take your time – Grok the tool-chain – Assign a “go-to guy” (or gal)
  • 27. IDE support • Wonky debugging – Java debuggers work… – … with some caveats • Step into synthetic stack frames • Do not step over closures – TypeSafe are focusing on debugging – JetBrains will likely follow
  • 28. IDE support • Except the unexpected – Spurious error highlighting • Especially with implicit conversions • Double-check with your build tool- chain – Rebuild the project occasionally – The situation is improving daily
  • 29. Build tools • Native Scala build tool is sbt – Ivy2 (-> Maven repositories) – Scala syntax – Very powerful, sharp learning curve • Stay away from ant • Maven and buildr should work fine
  • 30. Library ecosystem • Surprisingly mature landscape! • We use: – ScalaTest + ScalaMock – Squeryl – Scalatra • Use your favorite Java libraries natively!
  • 31. Focal points • Learning curve • Tooling • In production
  • 32. GC considerations • Lots of generated classes – Higher PermGen utilization – Increase -XX:MaxPermSize • Lots of intermediate objects – High eden space churn (normally OK) – Tune with –XX:NewRatio
  • 33. Other considerations • Scalac emits lots of synthetic code – Deep call graph – Intermediate stack frames • Default stack often too small – -Xss=2m should do
  • 34. Nasty surprises • Different compiler, different edge- cases – Stack overflow may segfault – Crash log may fail to generate (JDK 1.6.0_x) – Logs and thread dumps are your friends
  • 36. Codebase evolution Import Java codebase Refactoring Tipping point Slow growth Initial Scala experimentation
  • 37. Conclusion • I would recommend Scala for: – Startups willing to take the plunge – Small teams of senior developers – Large enterprises with tech advisory/leadership teams • But not (yet) for: – Contractors – Traditional enterprises
  • 38. Questions? … answers may be forthcoming
  • 39. Afterword • newBrandAnalytics for allowing the use of the company name and R&D evidence • TypeSafe and the amazing Scala community for making Scala what it is • … and SmileTemplate.com for the PowerPoint template • Get in touch! – tomer@tomergabel.com – http://www.tomergabel.com

Hinweis der Redaktion

  1. Evolve codebase (in other words, keep existing infrastructure and fix/extend as needed):Frustrating, legacy codebase written under tight time constraints is a maintenance nightmareNew engineering team needs a fresh start; keeping the team in maintenance mode is hazardous to team’s mental healthRefactor and extend (break down into smaller pieces; replace infrastructure incrementally, build extension points where needed):A highly practical solution. Existing code will continue to serve existing customers;Problematic bits can be replaced piecemeal, complex new functionality built separately and integrated at the lowest possible level (usually the database);A good compromise between risk mitigation and engineering sanitySupplant with new architecture (keep existing codebase in place and fix critical bugs only; where new functionality is required, interoperate with existing architecture):Impractical. Existing codebase had too many issues;In practice this is the same as evolving the codebase, because of the prohibitively high maintenance cost on the existing architecture.Complete rewrite: too risky, too slow. ‘nuff said.