javawug bof 57 scala why now

15
SCALA, WHY NOW? Monday, 5 th July Peter Pilgrim, Oracle Java Champion,

Upload: skills-matter

Post on 28-Jan-2015

110 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Javawug bof 57 scala why now

SCALA, WHY NOW?

Monday, 5th July Peter Pilgrim, Oracle Java Champion, 

Page 2: Javawug bof 57 scala why now

Brief History Scala

Scala – Scalable LanguagePre‐history

1996 – 1997 Pizza, 1998‐2000 GJ2003 Experiment2006‐2009 Industrial strength programming language

“Make a better Java” 

Page 3: Javawug bof 57 scala why now

Martin Odersky’s Scala Workshop

Page 4: Javawug bof 57 scala why now

Why Scala?

Functional

• Closures• Lambda Currying• Immutables• Style

Object Oriented

• Full Types• Hierarchical, Mix‐Ins

• Case Classes

Scalable

• Operators Overloading

• Pattern Matching• Extendable with Libraries

Cross Platform

• Static compilation to byte codes

• JVM • Dot Net

Page 5: Javawug bof 57 scala why now

Functional Side

Closures , Lambda Expression, Function TypesImmutable References to Objects (val)Immutable Objects & Collections 

Standard Scala Libraries

Currying –Control AbstractionsLast Statement is an ExpressionTail Recursion

Page 6: Javawug bof 57 scala why now

Object Oriented Side

Everything is an Object in ScalaBetter Static Classes (Object)Classes with reduced boilerplateTraits , Mix‐ins, Self‐Types

Page 7: Javawug bof 57 scala why now

REPL ‐ Read, Evaluate, Print, Loop

Execute Scala like a Scripting languageIncreasing support 

Eclipse IDE , NetBeans, IntelliJ

New Tools, Ideas and InnovationsSBT, Actors, Lift

Page 8: Javawug bof 57 scala why now

Repeat Until Construction #1a

package demo;

object Control {

def repeatLoop ( body: => Unit ) = new Until( body )

def class Until( body: => Unit ) {def until( cond: => Boolean ) {body;if ( cond )

repeatLoop(body).until(cond)}

}

}

Page 9: Javawug bof 57 scala why now

Repeat Until Construction #1b

import demo.Control;

object LoopDemo {

def main( args: Array[String] ) {

var y=0;

repeatLoop {println("found y="+y)y += 1

}

{ until ( y < 10 ) }}

}

Page 10: Javawug bof 57 scala why now

Quick Introduction to Currying

Haskell Curry (1901 – 1982)American Mathematician & LogicianCombinatory LogicPartial Functions

U(x,y,z) == F(x) ‐> G(y) ‐> H(z)

Page 11: Javawug bof 57 scala why now

Repeat Until Construction #2

object Control {

def repeat(body: => Unit) = new {def until(condition: => Boolean) = {

do {body

} while (!condition)}

}

}

// Jesper and Rex Kerr

Page 12: Javawug bof 57 scala why now

Concurrency in Scala

Actor based concurrency library (Bill Venners)Asynchronous messagesDispatch to threads; Fork Join

Page 13: Javawug bof 57 scala why now

Taste of Concurrency #1

import scala.actors._import scala.actors.Actor._

object TradeMessageProcessor extends Actor {def act() {

loop {receive {

case f: FXOrder => f.spotPrice()case m: MMOrder => m.maturityPrice()case “stop” => println(“Stopping now...”; exitcase x: Any -> println(“Error: unknown msg: “+x)

}}

}}

Page 14: Javawug bof 57 scala why now

Taste of Concurrency #2

TradeMessageProcessor.start()

TradeMessageProcessor ! new FXForwardOrder ( /*...*/ )

TradeMessageProcessor ! new FXSpotOrder( /*...*/ )

TradeMessageProcessor ! new MMOrder( /*...*/ )

TradeMessageProcessor ! 2.87134 // Unknown Msg Error!

TradeMessageProcessor ! “stop” // Processor stops

Page 15: Javawug bof 57 scala why now

Thanks For Your Attention!

For more informationhttp://scala‐lang.orghttp://daily‐scala.blogspot.com/http://stack‐overflow.com search on Scala

Scala is the Java of the Future

http://jroller.com/javawug