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 Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java DevelopersMichael Galpin
 
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 WorldBTI360
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
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...Thoughtworks
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scalaRuslan Shevchenko
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in ScalaShai Yallin
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
Scala intro for Java devs 20150324
Scala intro for Java devs 20150324Scala intro for Java devs 20150324
Scala intro for Java devs 20150324Erik Schmiegelow
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 

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

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?Mario Camou Riveroll
 
Scala elegant and exotic part 1
Scala  elegant and exotic part 1Scala  elegant and exotic part 1
Scala elegant and exotic part 1VulcanMinds
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々ScalaプログラミングTomoharu ASAMI
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java ProgrammersEric Pederson
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
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 DevelopersMiles Sabin
 
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 DevelopersMiles Sabin
 
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
 
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

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

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!