SlideShare a Scribd company logo
1 of 32
Download to read offline
Scala in the Wild
     Daniel Spiewak
Vanity Slide
• Software Developer at Novell
 • Working on a next-gen communications
    system called “Pulse”
• Author of Scala for Java Refugees
 • ...and a fair bit more
• An unhealthy fascination with languages
Brief Overview of Pulse
• Next-Gen communications platform
• Implemented as a web application
 • AJAX
 • Comet
• Focus on security and enterprise
  management
Architecture
                                    Messaging Service


                                  Search Service (SOLR)
Webapp (Lift)          RabbitMQ
                                   Notification Service


                                      WFP Service




            HBase           +      MySQL
Nifty Tricks


• Messages are chunks of XML
<message id="42">
  <line/>Playing with Pulse (and trying to avoid
  accidentally poluting any of Andy's demos).

  <message id="43">
    <line/>We can reply quite easily.
  </message>
</message>
Nifty Tricks

• Messages are chunks of XML
 • Extend Elem
 • Custom NoBindingFactoryAdapter
 • Use #load(String)
Nifty Tricks

• Messages are chunks of XML
• All frontend services use Cake Pattern
• Very extensive use of actors
Challenges

• Actors require a recovery mechanism
• Java / Scala interop is a little clumsy
• Collections conversion (java-utils)
import scala.collection.jcl.Conversions._

def foo(bar: java.util.List[String]) = {
  val xs: Seq[String] = bar
  bar.add("baz")

    xs foreach println     // does it contain "baz"?
}


def foo(bar: List[String]) = {
  val back = new java.util.ArrayList[String]
  bar foreach back.add

    back
}
import org.scala_tools.javautils.Implicits._

def foo(bar: java.util.List[String]) = {
  val xs = bar.asScala
  bar.add("baz")

    xs foreach println
}


// returns java.util.List[String], and in O(1) too!
def foo(bar: List[String]) = bar.asJava
Challenges
• Actors require a recovery mechanism
• Java / Scala interop is a little clumsy
• Collections conversion (java-utils)
• Spring doesn’t like mixins
• Tools are primitive (at best)
• Scala devs are in short supply
Java Refugees


• Tendency to write Java in Scala
class Person(fn :String, ln :String) {
    private var theFirstName :String = fn;
    private var theLastName :String = ln;

    def getFirstName() :String = {
        return theFirstName;
    }

    def setFirstName(fn :String) :Unit = {
        theFirstName = fn;
    }

    // ...

    override
    def equals(obj: Any) :Boolean = {
        if (obj.isInstanceOf[Person]) {
             var p :Person = obj.asInstanceOf[Person];

             return p.getFirstName() == theFirstName &&
                    p.getLastName() == theLastName;
        }

        return false;
    }
}
class Person(var firstName: String, var lastName: String) {
  override def equals(a: Any) = a match {
    case that: Person => {
      this.firstName == that.firstName &&
        this.lastName == that.lastName
    }

        case _ => false
    }
}
Java Refugees

• Tendency to write Java in Scala
• Failure to exploit advanced features
 • Nested imports
 • Point-Free / Currying
 • Monads
def foo(bar: Bar) = {
  var result: Baz = null

    Box.!!(bar).foreach(person =>
      Box.!!(person.name).foreach(name =>
        Box.!!(name.find("blah")).foreach(result = _)))

    Box !! result
}
def foo(bar: Bar) = {
  for {
    person <- Box !! bar
    name <- Box !! person.name
    result <- Box !! (name find "blah")
  } yield result
}
Java Refugees
• Tendency to write Java in Scala
• Failure to exploit advanced features
 • Nested imports
 • Point-Free / Currying
 • Monads
 • Higher-Kinds only raise confusion
• Arbitrary file organization
Solution: Conventions!


http://davetron5000.github.com/scala-style/
Scala Style
• Inspirations
 • Java
 • Standard ML
 • Haskell
 • C#
 • OCaml
 • Ruby
 • Python
Scala Style


• Leverage type inference!
 val s: String = "blah"      // wrong
 val s = "blah"              // right
Scala Style

• Leverage type inference!
• Higher-Order functions
   // wrong
   def foldLeft[A](init: A, f: (A, B) => A) = ...
   // right
   def foldLeft[A](init: A)(f: (A, B) => A) = ...

   foldLeft(0) { (a, b) => ... }
Scala Style
• Leverage type inference!
• Higher-Order functions
• Function values
   foo (x) => x + 1     // wrong
   foo (x) => { x + 1 } // wrong

   foo { _ + 1 }        // right
   foo { x => x + 1 }   // right
Scala Style
• Leverage type inference!
• Higher-Order functions
• Function values
• Correct use of implicits
 • Pimp-my-library
 • Correcting inheritance (typeclasses)
Scala Style
• ...
• Function values
• Rules for correct use of implicits
• Arity-0 methods
   println       // wrong
   println()     // right

   xs.length()   // wrong
   xs.length     // right
Scala Style
• Leverage type inference!
• Higher-Order functions
• Function values
• Rules for correct use of implicits
• Arity-0 methods
• File organization
Conclusion(s)

• Yes, Scala is ready for the enterprise!
 • ...but there’s definitely room to improve
• Process and conventions are critical
• Community is developing standards.
  Participate!
Thank You

More Related Content

What's hot

Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 

What's hot (20)

Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala jargon cheatsheet
Scala jargon cheatsheetScala jargon cheatsheet
Scala jargon cheatsheet
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Scala intro for Java devs 20150324
Scala intro for Java devs 20150324Scala intro for Java devs 20150324
Scala intro for Java devs 20150324
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
[Start] Scala
[Start] Scala[Start] Scala
[Start] Scala
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 

Similar to Scala In The Wild

楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
Tomoharu ASAMI
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
Joe Zulli
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
mircodotta
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
Tomasz Wrobel
 

Similar to Scala In The Wild (20)

Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?Static or Dynamic Typing? Why not both?
Static or Dynamic Typing? Why not both?
 
Scala elegant and exotic part 1
Scala  elegant and exotic part 1Scala  elegant and exotic part 1
Scala elegant and exotic part 1
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
Scala
ScalaScala
Scala
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
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
 
Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)Effective Scala (JavaDay Riga 2013)
Effective Scala (JavaDay Riga 2013)
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Scala In The Wild

  • 1. Scala in the Wild Daniel Spiewak
  • 2. Vanity Slide • Software Developer at Novell • Working on a next-gen communications system called “Pulse” • Author of Scala for Java Refugees • ...and a fair bit more • An unhealthy fascination with languages
  • 3. Brief Overview of Pulse • Next-Gen communications platform • Implemented as a web application • AJAX • Comet • Focus on security and enterprise management
  • 4.
  • 5.
  • 6.
  • 7. Architecture Messaging Service Search Service (SOLR) Webapp (Lift) RabbitMQ Notification Service WFP Service HBase + MySQL
  • 8. Nifty Tricks • Messages are chunks of XML
  • 9. <message id="42"> <line/>Playing with Pulse (and trying to avoid accidentally poluting any of Andy's demos). <message id="43"> <line/>We can reply quite easily. </message> </message>
  • 10. Nifty Tricks • Messages are chunks of XML • Extend Elem • Custom NoBindingFactoryAdapter • Use #load(String)
  • 11. Nifty Tricks • Messages are chunks of XML • All frontend services use Cake Pattern • Very extensive use of actors
  • 12. Challenges • Actors require a recovery mechanism • Java / Scala interop is a little clumsy • Collections conversion (java-utils)
  • 13. import scala.collection.jcl.Conversions._ def foo(bar: java.util.List[String]) = { val xs: Seq[String] = bar bar.add("baz") xs foreach println // does it contain "baz"? } def foo(bar: List[String]) = { val back = new java.util.ArrayList[String] bar foreach back.add back }
  • 14. import org.scala_tools.javautils.Implicits._ def foo(bar: java.util.List[String]) = { val xs = bar.asScala bar.add("baz") xs foreach println } // returns java.util.List[String], and in O(1) too! def foo(bar: List[String]) = bar.asJava
  • 15. Challenges • Actors require a recovery mechanism • Java / Scala interop is a little clumsy • Collections conversion (java-utils) • Spring doesn’t like mixins • Tools are primitive (at best) • Scala devs are in short supply
  • 16. Java Refugees • Tendency to write Java in Scala
  • 17. class Person(fn :String, ln :String) { private var theFirstName :String = fn; private var theLastName :String = ln; def getFirstName() :String = { return theFirstName; } def setFirstName(fn :String) :Unit = { theFirstName = fn; } // ... override def equals(obj: Any) :Boolean = { if (obj.isInstanceOf[Person]) { var p :Person = obj.asInstanceOf[Person]; return p.getFirstName() == theFirstName && p.getLastName() == theLastName; } return false; } }
  • 18. class Person(var firstName: String, var lastName: String) { override def equals(a: Any) = a match { case that: Person => { this.firstName == that.firstName && this.lastName == that.lastName } case _ => false } }
  • 19. Java Refugees • Tendency to write Java in Scala • Failure to exploit advanced features • Nested imports • Point-Free / Currying • Monads
  • 20. def foo(bar: Bar) = { var result: Baz = null Box.!!(bar).foreach(person => Box.!!(person.name).foreach(name => Box.!!(name.find("blah")).foreach(result = _))) Box !! result }
  • 21. def foo(bar: Bar) = { for { person <- Box !! bar name <- Box !! person.name result <- Box !! (name find "blah") } yield result }
  • 22. Java Refugees • Tendency to write Java in Scala • Failure to exploit advanced features • Nested imports • Point-Free / Currying • Monads • Higher-Kinds only raise confusion • Arbitrary file organization
  • 24. Scala Style • Inspirations • Java • Standard ML • Haskell • C# • OCaml • Ruby • Python
  • 25. Scala Style • Leverage type inference! val s: String = "blah" // wrong val s = "blah" // right
  • 26. Scala Style • Leverage type inference! • Higher-Order functions // wrong def foldLeft[A](init: A, f: (A, B) => A) = ... // right def foldLeft[A](init: A)(f: (A, B) => A) = ... foldLeft(0) { (a, b) => ... }
  • 27. Scala Style • Leverage type inference! • Higher-Order functions • Function values foo (x) => x + 1 // wrong foo (x) => { x + 1 } // wrong foo { _ + 1 } // right foo { x => x + 1 } // right
  • 28. Scala Style • Leverage type inference! • Higher-Order functions • Function values • Correct use of implicits • Pimp-my-library • Correcting inheritance (typeclasses)
  • 29. Scala Style • ... • Function values • Rules for correct use of implicits • Arity-0 methods println // wrong println() // right xs.length() // wrong xs.length // right
  • 30. Scala Style • Leverage type inference! • Higher-Order functions • Function values • Rules for correct use of implicits • Arity-0 methods • File organization
  • 31. Conclusion(s) • Yes, Scala is ready for the enterprise! • ...but there’s definitely room to improve • Process and conventions are critical • Community is developing standards. Participate!