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)

PDF
A Brief Introduction to Scala for Java Developers
PDF
Miles Sabin Introduction To Scala For Java Developers
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
PDF
An Introduction to Scala for Java Developers
PDF
An Introduction to Scala - Blending OO and Functional Paradigms
PPTX
Scala, Play 2.0 & Cloud Foundry
PDF
Getting Started With Scala
PDF
Getting Started With Scala
PDF
scalaliftoff2009.pdf
PDF
scalaliftoff2009.pdf
PDF
scalaliftoff2009.pdf
PDF
scalaliftoff2009.pdf
PDF
Scala for Java Programmers
PDF
Typesafe stack - Scala, Akka and Play
PDF
Scala - core features
PDF
Quick introduction to scala
PPTX
All about scala
ODP
PDF
Scala at GenevaJUG by Iulian Dragos
PDF
Yes scala can!
A Brief Introduction to Scala for Java Developers
Miles Sabin 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 - Blending OO and Functional Paradigms
Scala, Play 2.0 & Cloud Foundry
Getting Started With Scala
Getting Started With Scala
scalaliftoff2009.pdf
scalaliftoff2009.pdf
scalaliftoff2009.pdf
scalaliftoff2009.pdf
Scala for Java Programmers
Typesafe stack - Scala, Akka and Play
Scala - core features
Quick introduction to scala
All about scala
Scala at GenevaJUG by Iulian Dragos
Yes scala can!
Ad

Recently uploaded (20)

PDF
A symptom-driven medical diagnosis support model based on machine learning te...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PPTX
MuleSoft-Compete-Deck for midddleware integrations
PDF
Human Computer Interaction Miterm Lesson
PDF
substrate PowerPoint Presentation basic one
PDF
Lung cancer patients survival prediction using outlier detection and optimize...
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
Build Real-Time ML Apps with Python, Feast & NoSQL
PDF
CEH Module 2 Footprinting CEH V13, concepts
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
SaaS reusability assessment using machine learning techniques
PPTX
Internet of Everything -Basic concepts details
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
A symptom-driven medical diagnosis support model based on machine learning te...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Planning-an-Audit-A-How-To-Guide-Checklist-WP.pdf
Module 1 Introduction to Web Programming .pptx
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
MuleSoft-Compete-Deck for midddleware integrations
Human Computer Interaction Miterm Lesson
substrate PowerPoint Presentation basic one
Lung cancer patients survival prediction using outlier detection and optimize...
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
Advancing precision in air quality forecasting through machine learning integ...
Build Real-Time ML Apps with Python, Feast & NoSQL
CEH Module 2 Footprinting CEH V13, concepts
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
Auditboard EB SOX Playbook 2023 edition.
SaaS reusability assessment using machine learning techniques
Internet of Everything -Basic concepts details
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj

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!