SlideShare a Scribd company logo
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
Scala In The Wild
Scala In The Wild
Scala In The Wild
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

PPTX
Practically Functional
PDF
High Wizardry in the Land of Scala
PDF
Scala: Functioneel programmeren in een object georiënteerde wereld
PDF
Scala in Practice
PDF
A Scala Corrections Library
PDF
Functional Programming in Java 8 - Lambdas and Streams
ODP
A Tour Of Scala
PDF
Scala : language of the future
Practically Functional
High Wizardry in the Land of Scala
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala in Practice
A Scala Corrections Library
Functional Programming in Java 8 - Lambdas and Streams
A Tour Of Scala
Scala : language of the future

What's hot (20)

PDF
Introduction to Scala for Java Developers
PPTX
PDF
Scala vs Java 8 in a Java 8 World
PPT
Scala introduction
PDF
Scala jargon cheatsheet
PPTX
A Brief Intro to Scala
PDF
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
PDF
Few simple-type-tricks in scala
PPTX
Intro to Functional Programming in Scala
PPTX
Scala fundamentals
KEY
Scala Introduction
PDF
Scala in Places API
PDF
Scala cheatsheet
PDF
Scala coated JVM
PDF
Introduction to Functional Programming with Scala
PPTX
Scala intro for Java devs 20150324
PPT
Scala in a nutshell by venkat
PPT
Scala Talk at FOSDEM 2009
PDF
[Start] Scala
PDF
Scala @ TechMeetup Edinburgh
Introduction to Scala for Java Developers
Scala vs Java 8 in a Java 8 World
Scala introduction
Scala jargon cheatsheet
A Brief Intro to Scala
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Few simple-type-tricks in scala
Intro to Functional Programming in Scala
Scala fundamentals
Scala Introduction
Scala in Places API
Scala cheatsheet
Scala coated JVM
Introduction to Functional Programming with Scala
Scala intro for Java devs 20150324
Scala in a nutshell by venkat
Scala Talk at FOSDEM 2009
[Start] Scala
Scala @ TechMeetup Edinburgh
Ad

Similar to Scala In The Wild (20)

KEY
Static or Dynamic Typing? Why not both?
PPTX
Scala elegant and exotic part 1
PDF
楽々Scalaプログラミング
PPTX
Intro to scala
PPTX
Taxonomy of Scala
PPT
PDF
Scala for Java Programmers
PPTX
Scala for curious
PPTX
From Ruby to Scala
PPTX
Scala, Play 2.0 & Cloud Foundry
PDF
Scala - just good for Java shops?
PDF
Quick introduction to scala
PPTX
Scala final ppt vinay
ODP
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
PDF
An Introduction to Scala for Java Developers
PPTX
Scala Refactoring for Fun and Profit (Japanese subtitles)
PPTX
Scala Refactoring for Fun and Profit
PDF
Effective Scala (JavaDay Riga 2013)
PDF
(How) can we benefit from adopting scala?
Static or Dynamic Typing? Why not both?
Scala elegant and exotic part 1
楽々Scalaプログラミング
Intro to scala
Taxonomy of Scala
Scala for Java Programmers
Scala for curious
From Ruby to Scala
Scala, Play 2.0 & Cloud Foundry
Scala - just good for Java shops?
Quick introduction to scala
Scala final ppt vinay
BCS SPA 2010 - An 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
Effective Scala (JavaDay Riga 2013)
(How) can we benefit from adopting scala?
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

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
  • 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!