SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Taking Scala into the Enterprise

           Peter Pilgrim
       Oracle Java Champion
       ACCU Conference 2013
About the Speaker
•   Java Champion
•   Independent Contractor
•   Java since 1998
•   Scala since 2010




        13 April 2013   Xenonique ©2013   2
Agenda




• What’s New in Scala 2.10?
• Play Framework
• AKKA Framework

 13 April 2013    Xenonique ©2013   3
TypeSafe




13 April 2013     Xenonique ©2013   4
Simplicity




“I want a language with simple means to do interesting
things, which is not the same as a language to do only
simple things.” Prof. Martin Odersky
        13 April 2013      Xenonique ©2013               5
TypeSafe: The Company
• Founded in Summer 2011
• Based in Switzerland and
  headquartered in New York, USA
• Scala, Akka and Play Framework
• Professional Support for Scala




     13 April 2013   Xenonique ©2013   6
Growth of Scala Training
• Scala Solutions
• Dick Wall and Bill Venners,
  Escalate Solutions
• ScalaDays conference in London
  2012
• Scala content at JavaOne 2012



     13 April 2013   Xenonique ©2013   7
Scala Knowledge
• Hunger for more know-how
• Growing Awareness in Functional
  Programming
• Object Oriented Languages embrace
  FP principles
• JDK 8 Lambdas
• Clojure jobs at CitiBank, London &
  NY
     13 April 2013   Xenonique ©2013   8
Scala in Enterprise
•   Morgan Stanley
•   HSBC
•   Guardian UK
•   Twitter
•   Linked-In
•   Four Square



       13 April 2013   Xenonique ©2013   9
Scala Revision
                Demonstration of the simplicity




13 April 2013              Xenonique ©2013        10
Scalable Language




                  Still has a very bright future
Functional
                                             Purely Object-Oriented
      Statically-typed
                                                 JVM Language

      4/13/2013       XeNoNiQUe.co.uk (c) 2011                    11
Typing Derived from “Pascal”
  Tree of Computer Language

 <variableName> [: [ <Type> ]

              personName: String
                taxRate: Float
                density: Double
                 found: False
                persion: Person

    13 April 2013    Xenonique ©2013   12
Variables and Values
• Assignment less programming
• Prefer val over var

var   x = 10.0; x = 10 + x
val   y = 10.0
val   z: Float = x
var   t: Int = 42; t = t * 2

                                13
Scala Class
class Person (
    val firstName: String
    val lastName: String,
    val height: Float,
    val age: Int ) {
    // Write your definition here
}

     13 April 2013       Xenonique ©2013   14
Instances of Scala Classes

val p1 = new Person( "Billy",
"Mitchell", 5.10F, 42 )

val p2 = new Person( "Kat",
"Moon", 5.8F, 39 )



     13 April 2013   Xenonique ©2013   15
Companion Objects
object Person {
     private records = List[Person]()
     def apply(fn: String, ln: String,
          h: Float, a: Int): Person = {
         val p = new Person(fn, ln, h, a );
         records = p :: records.reverse //
O(1)
         return p
     }
     def recordCount() = records.size
}

       13 April 2013   Xenonique ©2013        16
Case Classes

class Transmission( driveTrain:
String )




     13 April 2013       Xenonique ©2013   17
Scala Functions

val isEven: (Int => Boolean) =             (k: Int) => k % 2 == 0




• Functions are values, values are object
• Ergo, functions are objects in Scala




         13 April 2013   Xenonique ©2013                            18
Scala Code
def uniqueSorted[Symbol]( p: List[Symbol] ): List[Symbol] = {
    val myOrdering =
       Ordering.fromLessThan[Symbol](
                _.toString < _.toString )
    var acc = SortedSet.empty(myOrdering)

     def compress0( q: List[Symbol] ): Unit = {
       q match {
         case Nil => Nil
         case x :: xs => { acc += x ; compress0(xs)   }
       }
     }

     compress0( p )
     acc.toList
 }
           13 April 2013      Xenonique ©2013                   19
Functions are First Class
• In Scala, functions are first
  class citizens
• Functions can return functions




     13 April 2013   Xenonique ©2013   20
SBT
•   SBT is the de-facto build tool
•   Works with Maven
•   Incremental Compilation +1
•   DSL written in Scala +1
•   Plugins Available +1
•   Complex to Understand -1



        13 April 2013   Xenonique ©2013   21
Gradle
• Gradle is written in Groovy
• Gradle is a DSL too +1
• Easier to Grok +1
• Since v1.4 Gradle support
  incremental compilation through
  Zinc
• Not the de-facto standard -1


     13 April 2013    Xenonique ©2013   22
String Interpolation
•   SIP 12: String interpolation
•   S”Book written by $author”
•   Arbitary identifier: StringContext
•   StringContext(“Books written
    by”).id(author)




        13 April 2013   Xenonique ©2013   23
Value Classes
•   Implicit Classes
•   Classes that extend AnyVal
•   Unboxed value classes
•   Language imports
•   import
    language.implicitConversions



        13 April 2013        Xenonique ©2013   24
Value Classes
Elegant wrappers around simple
types
• A Value class is treated as
  another type
• A value value is assigned to an
  array
• Doing runtime type tests, such as
  pattern matching

     13 April 2013        Xenonique ©2013   25
Incremental Compilation
• Incremental compilation, Zinc
• Language with simple means to do
  interesting things




     13 April 2013   Xenonique ©2013   26
Scala Test
•   The de-facto testing framework
•   Created Bill Venners, JVM Book
•   DSL unit testing language
•   Behaviour Driven Development +1
•   Test Driven Development




        13 April 2013      Xenonique ©2013   27
Play Framework
                Non Java EE web framework




13 April 2013            Xenonique ©2013    28
Play Framework 2.0
•   Non Java EE – No Servlet
•   Built for Web Development
•   Direct manipulation of HTTP
•   Asynchronous Input and Output
•   Scalable Vertically




                                    29
Play Framework Architecture

                                 Web Client


                                  Network


                   Netty (Java NIO Client Server Framework)



                              Play Framework




   13 April 2013                 Xenonique ©2013              30
Play Advantages
•   Highly productive web development
•   Work with Web Designers
•   Feels of “Rails”
•   Compiler type checked
•   Model, View and Controller




                                        31
Play Disadvantages
• Completed encapsulated environment
• Unlike JavaEE and WAR file
  deployment to application server
• No WAR file (yet) as of Play 2.1.x
• Ironically, WAR files need JavaEE
  7 (WebSocket and Async Servlet
  3.1)


                                   32
Play Style
• Dispatch through a Router file
• Directly manipulation of the HTTP
  response, Ok(200), Error(404)
• Control HTTP interface: GET, PUT,
  POST, DELETE
• Model, View and Controller scala
  objects
• Asynchronuous process API
                                      33
Play Persistence
• Play has its own persistence provider
  Anorm: a direct SQL framework
• Play can also use Squeryl: an Object-
  Relational Mapper DSL with type safety.




                                        34
Developer Summary
What You Will Do Tomorrow?

              Why FP?



                          Gradle /
Scala Test   Scala 2.10     SBT


               Play /
               Akka
Game Over

13 April 2013     Xenonique ©2013   37
Professional Services



        Contract Software Development
        Scala, JavaEE, JavaFX, TDD, Gradle

        W: http://www.xenonique.co.uk/blog/
        E: peter.pilgrim@gmail.com



   4/13/2013                                  38
Professional Services



           peter.pilgrim@gmail.com
           Scala, JavaEE 7, JavaFX
           Contracting
           Software Development


   4/13/2013                         39
Attributions
• The author would very like to attribute these
  pleasurable Creative Commons License 3.0
  photographers

•   Brush Metal Elevator door By Jerry "Eyes" Ranch; West Des Moines, IA,
    USA; http://www.flickr.com/photos/ranchjp/3684969194/
•   19/365 Game Over by Mykl Roventine;
    http://www.flickr.com/photos/myklroventine/3210068573
•   Experiment in abstract lightning by Bob Doran; Walnut Creek, Arcata,
    USA ; http://www.flickr.com/photos/humblog/4522984790/in/photostream/




                                                                       40
Attributions #2
•   Study in Math exam photo by Steve S;
    http://www.flickr.com/photos/scubasteveo/296747958/




                                                          41

Mais conteúdo relacionado

Semelhante a ACCU 2013 Taking Scala into the Enterpise

Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
ssusercd195b
 
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMQCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
Peter Pilgrim
 
Scala for android
Scala for androidScala for android
Scala for android
Tack Mobile
 
Cloud stack design camp on jun 15
Cloud stack design camp on jun 15Cloud stack design camp on jun 15
Cloud stack design camp on jun 15
Isaac Chiang
 
1java Introduction
1java Introduction1java Introduction
1java Introduction
Adil Jafri
 

Semelhante a ACCU 2013 Taking Scala into the Enterpise (20)

Trends and future of java
Trends and future of javaTrends and future of java
Trends and future of java
 
Angular, the New Angular JS
Angular, the New Angular JSAngular, the New Angular JS
Angular, the New Angular JS
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMQCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
 
Cloudfoundry Overview
Cloudfoundry OverviewCloudfoundry Overview
Cloudfoundry Overview
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Scala for android
Scala for androidScala for android
Scala for android
 
Gradle
GradleGradle
Gradle
 
wotxr-20190320rzr
wotxr-20190320rzrwotxr-20190320rzr
wotxr-20190320rzr
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-up
 
Selling Scala to your boss
Selling Scala to your bossSelling Scala to your boss
Selling Scala to your boss
 
An Introduction to AngularJS
An Introduction to AngularJSAn Introduction to AngularJS
An Introduction to AngularJS
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
 
Scala at Treasure Data
Scala at Treasure DataScala at Treasure Data
Scala at Treasure Data
 
Cloud stack design camp on jun 15
Cloud stack design camp on jun 15Cloud stack design camp on jun 15
Cloud stack design camp on jun 15
 
NetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker TalkNetflixOSS and ZeroToDocker Talk
NetflixOSS and ZeroToDocker Talk
 
1java Introduction
1java Introduction1java Introduction
1java Introduction
 
Sap java
Sap javaSap java
Sap java
 
Stackato v4
Stackato v4Stackato v4
Stackato v4
 

Mais de Peter Pilgrim

JavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development ExperiencesJavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development Experiences
Peter Pilgrim
 
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom ComponentsJavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
Peter Pilgrim
 

Mais de Peter Pilgrim (13)

Devoxx 2019 - Why we pair?
Devoxx 2019 - Why we pair?Devoxx 2019 - Why we pair?
Devoxx 2019 - Why we pair?
 
Cloud native java are we there yet go tech world 2019
Cloud native java   are we there yet  go tech world 2019Cloud native java   are we there yet  go tech world 2019
Cloud native java are we there yet go tech world 2019
 
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
 
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
 
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
 
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and NoteworthyJava EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
 
BOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala appsBOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala apps
 
AOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java PlatformAOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java Platform
 
JavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development ExperiencesJavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development Experiences
 
JavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformJavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java Platform
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
 
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom ComponentsJavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
 
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
ACCU 2011 Introduction to Scala: An Object Functional Programming LanguageACCU 2011 Introduction to Scala: An Object Functional Programming Language
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Último (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

ACCU 2013 Taking Scala into the Enterpise

  • 1. Taking Scala into the Enterprise Peter Pilgrim Oracle Java Champion ACCU Conference 2013
  • 2. About the Speaker • Java Champion • Independent Contractor • Java since 1998 • Scala since 2010 13 April 2013 Xenonique ©2013 2
  • 3. Agenda • What’s New in Scala 2.10? • Play Framework • AKKA Framework 13 April 2013 Xenonique ©2013 3
  • 4. TypeSafe 13 April 2013 Xenonique ©2013 4
  • 5. Simplicity “I want a language with simple means to do interesting things, which is not the same as a language to do only simple things.” Prof. Martin Odersky 13 April 2013 Xenonique ©2013 5
  • 6. TypeSafe: The Company • Founded in Summer 2011 • Based in Switzerland and headquartered in New York, USA • Scala, Akka and Play Framework • Professional Support for Scala 13 April 2013 Xenonique ©2013 6
  • 7. Growth of Scala Training • Scala Solutions • Dick Wall and Bill Venners, Escalate Solutions • ScalaDays conference in London 2012 • Scala content at JavaOne 2012 13 April 2013 Xenonique ©2013 7
  • 8. Scala Knowledge • Hunger for more know-how • Growing Awareness in Functional Programming • Object Oriented Languages embrace FP principles • JDK 8 Lambdas • Clojure jobs at CitiBank, London & NY 13 April 2013 Xenonique ©2013 8
  • 9. Scala in Enterprise • Morgan Stanley • HSBC • Guardian UK • Twitter • Linked-In • Four Square 13 April 2013 Xenonique ©2013 9
  • 10. Scala Revision Demonstration of the simplicity 13 April 2013 Xenonique ©2013 10
  • 11. Scalable Language Still has a very bright future Functional Purely Object-Oriented Statically-typed JVM Language 4/13/2013 XeNoNiQUe.co.uk (c) 2011 11
  • 12. Typing Derived from “Pascal” Tree of Computer Language <variableName> [: [ <Type> ] personName: String taxRate: Float density: Double found: False persion: Person 13 April 2013 Xenonique ©2013 12
  • 13. Variables and Values • Assignment less programming • Prefer val over var var x = 10.0; x = 10 + x val y = 10.0 val z: Float = x var t: Int = 42; t = t * 2 13
  • 14. Scala Class class Person ( val firstName: String val lastName: String, val height: Float, val age: Int ) { // Write your definition here } 13 April 2013 Xenonique ©2013 14
  • 15. Instances of Scala Classes val p1 = new Person( "Billy", "Mitchell", 5.10F, 42 ) val p2 = new Person( "Kat", "Moon", 5.8F, 39 ) 13 April 2013 Xenonique ©2013 15
  • 16. Companion Objects object Person { private records = List[Person]() def apply(fn: String, ln: String, h: Float, a: Int): Person = { val p = new Person(fn, ln, h, a ); records = p :: records.reverse // O(1) return p } def recordCount() = records.size } 13 April 2013 Xenonique ©2013 16
  • 17. Case Classes class Transmission( driveTrain: String ) 13 April 2013 Xenonique ©2013 17
  • 18. Scala Functions val isEven: (Int => Boolean) = (k: Int) => k % 2 == 0 • Functions are values, values are object • Ergo, functions are objects in Scala 13 April 2013 Xenonique ©2013 18
  • 19. Scala Code def uniqueSorted[Symbol]( p: List[Symbol] ): List[Symbol] = { val myOrdering = Ordering.fromLessThan[Symbol]( _.toString < _.toString ) var acc = SortedSet.empty(myOrdering) def compress0( q: List[Symbol] ): Unit = { q match { case Nil => Nil case x :: xs => { acc += x ; compress0(xs) } } } compress0( p ) acc.toList } 13 April 2013 Xenonique ©2013 19
  • 20. Functions are First Class • In Scala, functions are first class citizens • Functions can return functions 13 April 2013 Xenonique ©2013 20
  • 21. SBT • SBT is the de-facto build tool • Works with Maven • Incremental Compilation +1 • DSL written in Scala +1 • Plugins Available +1 • Complex to Understand -1 13 April 2013 Xenonique ©2013 21
  • 22. Gradle • Gradle is written in Groovy • Gradle is a DSL too +1 • Easier to Grok +1 • Since v1.4 Gradle support incremental compilation through Zinc • Not the de-facto standard -1 13 April 2013 Xenonique ©2013 22
  • 23. String Interpolation • SIP 12: String interpolation • S”Book written by $author” • Arbitary identifier: StringContext • StringContext(“Books written by”).id(author) 13 April 2013 Xenonique ©2013 23
  • 24. Value Classes • Implicit Classes • Classes that extend AnyVal • Unboxed value classes • Language imports • import language.implicitConversions 13 April 2013 Xenonique ©2013 24
  • 25. Value Classes Elegant wrappers around simple types • A Value class is treated as another type • A value value is assigned to an array • Doing runtime type tests, such as pattern matching 13 April 2013 Xenonique ©2013 25
  • 26. Incremental Compilation • Incremental compilation, Zinc • Language with simple means to do interesting things 13 April 2013 Xenonique ©2013 26
  • 27. Scala Test • The de-facto testing framework • Created Bill Venners, JVM Book • DSL unit testing language • Behaviour Driven Development +1 • Test Driven Development 13 April 2013 Xenonique ©2013 27
  • 28. Play Framework Non Java EE web framework 13 April 2013 Xenonique ©2013 28
  • 29. Play Framework 2.0 • Non Java EE – No Servlet • Built for Web Development • Direct manipulation of HTTP • Asynchronous Input and Output • Scalable Vertically 29
  • 30. Play Framework Architecture Web Client Network Netty (Java NIO Client Server Framework) Play Framework 13 April 2013 Xenonique ©2013 30
  • 31. Play Advantages • Highly productive web development • Work with Web Designers • Feels of “Rails” • Compiler type checked • Model, View and Controller 31
  • 32. Play Disadvantages • Completed encapsulated environment • Unlike JavaEE and WAR file deployment to application server • No WAR file (yet) as of Play 2.1.x • Ironically, WAR files need JavaEE 7 (WebSocket and Async Servlet 3.1) 32
  • 33. Play Style • Dispatch through a Router file • Directly manipulation of the HTTP response, Ok(200), Error(404) • Control HTTP interface: GET, PUT, POST, DELETE • Model, View and Controller scala objects • Asynchronuous process API 33
  • 34. Play Persistence • Play has its own persistence provider Anorm: a direct SQL framework • Play can also use Squeryl: an Object- Relational Mapper DSL with type safety. 34
  • 36. What You Will Do Tomorrow? Why FP? Gradle / Scala Test Scala 2.10 SBT Play / Akka
  • 37. Game Over 13 April 2013 Xenonique ©2013 37
  • 38. Professional Services Contract Software Development Scala, JavaEE, JavaFX, TDD, Gradle W: http://www.xenonique.co.uk/blog/ E: peter.pilgrim@gmail.com 4/13/2013 38
  • 39. Professional Services peter.pilgrim@gmail.com Scala, JavaEE 7, JavaFX Contracting Software Development 4/13/2013 39
  • 40. Attributions • The author would very like to attribute these pleasurable Creative Commons License 3.0 photographers • Brush Metal Elevator door By Jerry "Eyes" Ranch; West Des Moines, IA, USA; http://www.flickr.com/photos/ranchjp/3684969194/ • 19/365 Game Over by Mykl Roventine; http://www.flickr.com/photos/myklroventine/3210068573 • Experiment in abstract lightning by Bob Doran; Walnut Creek, Arcata, USA ; http://www.flickr.com/photos/humblog/4522984790/in/photostream/ 40
  • 41. Attributions #2 • Study in Math exam photo by Steve S; http://www.flickr.com/photos/scubasteveo/296747958/ 41