accu 2013 taking scala into the enterpise

41
Peter Pilgrim Oracle Java Champion ACCU Conference 2013 Taking Scala into the Enterprise

Upload: peter-pilgrim

Post on 27-May-2015

1.808 views

Category:

Education


1 download

DESCRIPTION

Talk at ACCU 2013 in Bristol

TRANSCRIPT

Page 1: ACCU 2013 Taking Scala into the Enterpise

Peter Pilgrim

Oracle Java Champion

ACCU Conference 2013

Taking Scala into the Enterprise

Page 2: ACCU 2013 Taking Scala into the Enterpise

About the Speaker

• Java Champion

• Independent Contractor

• Java since 1998

• Scala since 2010

13 April 2013 Xenonique ©2013 2

Page 3: ACCU 2013 Taking Scala into the Enterpise

Agenda

• What’s New in Scala 2.10?

• Play Framework

• AKKA Framework

13 April 2013 Xenonique ©2013 3

Page 4: ACCU 2013 Taking Scala into the Enterpise

TypeSafe

13 April 2013 Xenonique ©2013 4

Page 5: ACCU 2013 Taking Scala into the Enterpise

Simplicity

13 April 2013 Xenonique ©2013 5

“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

Page 6: ACCU 2013 Taking Scala into the Enterpise

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

Page 7: ACCU 2013 Taking Scala into the Enterpise

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

Page 8: ACCU 2013 Taking Scala into the Enterpise

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

Page 9: ACCU 2013 Taking Scala into the Enterpise

Scala in Enterprise

• Morgan Stanley

• HSBC

• Guardian UK

• Twitter

• Linked-In

• Four Square

13 April 2013 Xenonique ©2013 9

Page 10: ACCU 2013 Taking Scala into the Enterpise

13 April 2013 Xenonique ©2013 10

Scala Revision Demonstration of the simplicity

Page 11: ACCU 2013 Taking Scala into the Enterpise

Scalable Language

4/13/2013 XeNoNiQUe.co.uk (c) 2011 11

Still has a very bright future

Purely Object-Oriented Statically-typed

Functional

JVM Language

Page 12: ACCU 2013 Taking Scala into the Enterpise

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

Page 13: ACCU 2013 Taking Scala into the Enterpise

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

Page 14: ACCU 2013 Taking Scala into the Enterpise

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

Page 15: ACCU 2013 Taking Scala into the Enterpise

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

Page 16: ACCU 2013 Taking Scala into the Enterpise

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

Page 17: ACCU 2013 Taking Scala into the Enterpise

Case Classes

class Transmission( driveTrain: String )

13 April 2013 Xenonique ©2013 17

Page 18: ACCU 2013 Taking Scala into the Enterpise

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

• Functions are values, values are object

• Ergo, functions are objects in Scala

Scala Functions

13 April 2013 Xenonique ©2013 18

Page 19: ACCU 2013 Taking Scala into the Enterpise

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

Page 20: ACCU 2013 Taking Scala into the Enterpise

Functions are First Class

• In Scala, functions are first class citizens

• Functions can return functions

13 April 2013 Xenonique ©2013 20

Page 21: ACCU 2013 Taking Scala into the Enterpise

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

Page 22: ACCU 2013 Taking Scala into the Enterpise

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

Page 23: ACCU 2013 Taking Scala into the Enterpise

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

Page 24: ACCU 2013 Taking Scala into the Enterpise

Value Classes

• Implicit Classes

• Classes that extend AnyVal

• Unboxed value classes

• Language imports

• import language.implicitConversions

13 April 2013 Xenonique ©2013 24

Page 25: ACCU 2013 Taking Scala into the Enterpise

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

Page 26: ACCU 2013 Taking Scala into the Enterpise

Incremental Compilation

• Incremental compilation, Zinc

• Language with simple means to do interesting things

13 April 2013 Xenonique ©2013 26

Page 27: ACCU 2013 Taking Scala into the Enterpise

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

Page 28: ACCU 2013 Taking Scala into the Enterpise

13 April 2013 Xenonique ©2013 28

Play Framework Non Java EE web framework

Page 29: ACCU 2013 Taking Scala into the Enterpise

Play Framework 2.0

• Non Java EE – No Servlet

• Built for Web Development

• Direct manipulation of HTTP

• Asynchronous Input and Output

• Scalable Vertically

29

Page 30: ACCU 2013 Taking Scala into the Enterpise

Play Framework Architecture

13 April 2013 Xenonique ©2013 30

Web Client

Play Framework

Netty (Java NIO Client Server Framework)

Network

Page 31: ACCU 2013 Taking Scala into the Enterpise

Play Advantages

• Highly productive web development

• Work with Web Designers

• Feels of “Rails”

• Compiler type checked

• Model, View and Controller

31

Page 32: ACCU 2013 Taking Scala into the Enterpise

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

Page 33: ACCU 2013 Taking Scala into the Enterpise

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

Page 34: ACCU 2013 Taking Scala into the Enterpise

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

Page 35: ACCU 2013 Taking Scala into the Enterpise

Developer Summary

Page 36: ACCU 2013 Taking Scala into the Enterpise

What You Will Do Tomorrow?

Scala 2.10

Why FP?

Gradle / SBT

Play / Akka

Scala Test

Page 37: ACCU 2013 Taking Scala into the Enterpise

13 April 2013 Xenonique ©2013 37

Game Over

Page 38: ACCU 2013 Taking Scala into the Enterpise

38

Professional Services

4/13/2013

Contract Software Development Scala, JavaEE, JavaFX, TDD, Gradle W: http://www.xenonique.co.uk/blog/ E: [email protected]

Page 39: ACCU 2013 Taking Scala into the Enterpise

39

Professional Services

4/13/2013

[email protected] Scala, JavaEE 7, JavaFX Contracting Software Development

Page 40: ACCU 2013 Taking Scala into the Enterpise

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

Page 41: ACCU 2013 Taking Scala into the Enterpise

Attributions #2

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

41