SlideShare uma empresa Scribd logo
1 de 41
Scala In Practice:
    A Case Study
Tomer Gabel, newBrandAnalytics
                    April 2012
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
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
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

Mais conteúdo relacionado

Mais procurados

An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Mike Slinn
 
Introduction to Scala | Big Data Hadoop Spark Tutorial | 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 | CloudxLabCloudxLab
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoTaro L. Saito
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Why Scala Is Taking Over the Big Data World
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 WorldDean Wampler
 
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...
Machine learning with Apache Spark MLlib | Big Data Hadoop Spark Tutorial | C...CloudxLab
 
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上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...scalaconfjp
 
Neo4 + Grails
Neo4 + GrailsNeo4 + Grails
Neo4 + Grailsstasimus
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overviewstasimus
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the WildTomer 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)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Tomer Gabel
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platformRuslan Shevchenko
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
 
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の紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介scalaconfjp
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 

Mais procurados (20)

Scala for C# Developers
Scala for C# DevelopersScala for C# Developers
Scala for C# Developers
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
Introduction to Scala | Big Data Hadoop Spark Tutorial | 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
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Why Scala Is Taking Over the Big Data World
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
 
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...
Machine learning with Apache Spark MLlib | Big Data Hadoop Spark Tutorial | C...
 
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上で実現された制約プログラ...
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
 
Neo4 + Grails
Neo4 + GrailsNeo4 + Grails
Neo4 + Grails
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Jslab rssh: JS as language platform
Jslab rssh:  JS as language platformJslab rssh:  JS as language platform
Jslab rssh: JS as language platform
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
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の紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 

Destaque

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascadingjohnynek
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
 
5 Bullets to Scala Adoption
5 Bullets to Scala Adoption5 Bullets to Scala Adoption
5 Bullets to Scala AdoptionTomer Gabel
 
How shit works: the CPU
How shit works: the CPUHow shit works: the CPU
How shit works: the CPUTomer Gabel
 
Знакомьтесь, Kotlin
Знакомьтесь, KotlinЗнакомьтесь, Kotlin
Знакомьтесь, KotlinTech Talks @NSU
 
Android opetuksessa 11.9.14
Android opetuksessa 11.9.14Android opetuksessa 11.9.14
Android opetuksessa 11.9.14Matleena Laakso
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugsComputer Science Club
 
Infinum Android Talks #20 - Benefits of using Kotlin
Infinum Android Talks #20 - Benefits of using KotlinInfinum Android Talks #20 - Benefits of using Kotlin
Infinum Android Talks #20 - Benefits of using KotlinInfinum
 
Do Languages Matter?
Do Languages Matter?Do Languages Matter?
Do Languages Matter?Bruce Eckel
 
Kotlin в production. Как и зачем?
Kotlin в production. Как и зачем?Kotlin в production. Как и зачем?
Kotlin в production. Как и зачем?DotNetConf
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1Mukesh Kumar
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 

Destaque (20)

Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Scala test
Scala testScala test
Scala test
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
5 Bullets to Scala Adoption
5 Bullets to Scala Adoption5 Bullets to Scala Adoption
5 Bullets to Scala Adoption
 
How shit works: the CPU
How shit works: the CPUHow shit works: the CPU
How shit works: the CPU
 
Scala
ScalaScala
Scala
 
Знакомьтесь, Kotlin
Знакомьтесь, KotlinЗнакомьтесь, Kotlin
Знакомьтесь, Kotlin
 
Android opetuksessa 11.9.14
Android opetuksessa 11.9.14Android opetuksessa 11.9.14
Android opetuksessa 11.9.14
 
Scala Day by Day
Scala Day by DayScala Day by Day
Scala Day by Day
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin Overview
 
Infinum Android Talks #20 - Benefits of using Kotlin
Infinum Android Talks #20 - Benefits of using KotlinInfinum Android Talks #20 - Benefits of using Kotlin
Infinum Android Talks #20 - Benefits of using Kotlin
 
Intro to kotlin
Intro to kotlinIntro to kotlin
Intro to kotlin
 
Do Languages Matter?
Do Languages Matter?Do Languages Matter?
Do Languages Matter?
 
Kotlin в production. Как и зачем?
Kotlin в production. Как и зачем?Kotlin в production. Как и зачем?
Kotlin в production. Как и зачем?
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 

Semelhante a Scala in practice

Introducing Scala to your Ruby/Java Shop : My experiences at IGN
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
 
From java to scala at crowd mix
From java to scala at crowd mixFrom java to scala at crowd mix
From java to scala at crowd mixStefano Galarraga
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with ScalaManish Pandit
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataJohn Nestor
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
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 SeattleDomino Data Lab
 
Code reviews
Code reviewsCode reviews
Code reviewsRoger Xia
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Martijn Verburg
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Scala & Spark Online Training
Scala & Spark Online TrainingScala & Spark Online Training
Scala & Spark Online TrainingLearntek1
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaJohn Nestor
 

Semelhante a Scala in practice (20)

Introducing Scala to your Ruby/Java Shop : My experiences at IGN
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
 
From java to scala at crowd mix
From java to scala at crowd mixFrom java to scala at crowd mix
From java to scala at crowd mix
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Scala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big DataScala and Spark are Ideal for Big Data
Scala and Spark are Ideal for Big Data
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Scala and Spark are Ideal for Big Data - Data Science Pop-up Seattle
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
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
What is scala
What is scalaWhat is scala
What is scala
 
Scala & Spark Online Training
Scala & Spark Online TrainingScala & Spark Online Training
Scala & Spark Online Training
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
 
Scala goods bads
Scala goods badsScala goods bads
Scala goods bads
 

Mais de Tomer Gabel

How shit works: Time
How shit works: TimeHow shit works: Time
How shit works: TimeTomer Gabel
 
Nondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of UsNondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of UsTomer Gabel
 
Slaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency InjectionSlaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency InjectionTomer Gabel
 
An Abridged Guide to Event Sourcing
An Abridged Guide to Event SourcingAn Abridged Guide to Event Sourcing
An Abridged Guide to Event SourcingTomer Gabel
 
How Shit Works: Storage
How Shit Works: StorageHow Shit Works: Storage
How Shit Works: StorageTomer Gabel
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice StackTomer 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)
Scala Refactoring for Fun and Profit (Japanese subtitles)Tomer Gabel
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitTomer Gabel
 
Onboarding at Scale
Onboarding at ScaleOnboarding at Scale
Onboarding at ScaleTomer Gabel
 
Put Your Thinking CAP On
Put Your Thinking CAP OnPut Your Thinking CAP On
Put Your Thinking CAP OnTomer Gabel
 
Leveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationTomer Gabel
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaTomer 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)
Functional Leap of Faith (Keynote at JDay Lviv 2014)Tomer Gabel
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Tomer Gabel
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With ScalaTomer Gabel
 
Lab: JVM Production Debugging 101
Lab: JVM Production Debugging 101Lab: JVM Production Debugging 101
Lab: JVM Production Debugging 101Tomer Gabel
 
DevCon³: Scala Best Practices
DevCon³: Scala Best PracticesDevCon³: Scala Best Practices
DevCon³: Scala Best PracticesTomer Gabel
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for DummiesTomer Gabel
 
SHC Israel: GigaSpaces Case Study
SHC Israel: GigaSpaces Case StudySHC Israel: GigaSpaces Case Study
SHC Israel: GigaSpaces Case StudyTomer Gabel
 
The Demoscene: A cursory introduction
The Demoscene: A cursory introductionThe Demoscene: A cursory introduction
The Demoscene: A cursory introductionTomer Gabel
 

Mais de Tomer Gabel (20)

How shit works: Time
How shit works: TimeHow shit works: Time
How shit works: Time
 
Nondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of UsNondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of Us
 
Slaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency InjectionSlaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency Injection
 
An Abridged Guide to Event Sourcing
An Abridged Guide to Event SourcingAn Abridged Guide to Event Sourcing
An Abridged Guide to Event Sourcing
 
How Shit Works: Storage
How Shit Works: StorageHow Shit Works: Storage
How Shit Works: Storage
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice Stack
 
Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
Onboarding at Scale
Onboarding at ScaleOnboarding at Scale
Onboarding at Scale
 
Put Your Thinking CAP On
Put Your Thinking CAP OnPut Your Thinking CAP On
Put Your Thinking CAP On
 
Leveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better Validation
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
 
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)
Functional Leap of Faith (Keynote at JDay Lviv 2014)
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Lab: JVM Production Debugging 101
Lab: JVM Production Debugging 101Lab: JVM Production Debugging 101
Lab: JVM Production Debugging 101
 
DevCon³: Scala Best Practices
DevCon³: Scala Best PracticesDevCon³: Scala Best Practices
DevCon³: Scala Best Practices
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
SHC Israel: GigaSpaces Case Study
SHC Israel: GigaSpaces Case StudySHC Israel: GigaSpaces Case Study
SHC Israel: GigaSpaces Case Study
 
The Demoscene: A cursory introduction
The Demoscene: A cursory introductionThe Demoscene: A cursory introduction
The Demoscene: A cursory introduction
 

Último

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Último (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Scala in practice

  • 1. Scala In Practice: A Case Study Tomer Gabel, newBrandAnalytics April 2012
  • 2.
  • 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
  • 14.
  • 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
  • 35.
  • 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

Notas do Editor

  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.