javawug bof 57 scala why now
DESCRIPTION
TRANSCRIPT
SCALA, WHY NOW?
Monday, 5th July Peter Pilgrim, Oracle Java Champion,
Brief History Scala
Scala – Scalable LanguagePre‐history
1996 – 1997 Pizza, 1998‐2000 GJ2003 Experiment2006‐2009 Industrial strength programming language
“Make a better Java”
Martin Odersky’s Scala Workshop
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
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
Object Oriented Side
Everything is an Object in ScalaBetter Static Classes (Object)Classes with reduced boilerplateTraits , Mix‐ins, Self‐Types
REPL ‐ Read, Evaluate, Print, Loop
Execute Scala like a Scripting languageIncreasing support
Eclipse IDE , NetBeans, IntelliJ
New Tools, Ideas and InnovationsSBT, Actors, Lift
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)}
}
}
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 ) }}
}
Quick Introduction to Currying
Haskell Curry (1901 – 1982)American Mathematician & LogicianCombinatory LogicPartial Functions
U(x,y,z) == F(x) ‐> G(y) ‐> H(z)
Repeat Until Construction #2
object Control {
def repeat(body: => Unit) = new {def until(condition: => Boolean) = {
do {body
} while (!condition)}
}
}
// Jesper and Rex Kerr
Concurrency in Scala
Actor based concurrency library (Bill Venners)Asynchronous messagesDispatch to threads; Fork Join
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)
}}
}}
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
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