Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Why Scala?

Advanced Object/Functional Software Development
by

Michael Nash

on 16 October 2010

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Why Scala?

Scripting REPL Speed of Evolution Licensing Actors Open Source
BSD-style License JVM (and the CLR)
Dalvik (Android) Expressiveness Functional Options Pattern Matching Not Oracle Traits Powerful Type System Eclipse
IntelliJ IDEA
vim Plugin
Netbeans Plugin
Emacs ENSIME
Maven
sbt
Buildr
Many others Collections Implicit Typing Very well suited to internal and external DSLs
Scala is Extensible
Any method can be an infix or postfix operator Design Heritage Package Objects Type Inferencing
Types don't get in the way Who? What? Why? Read Evaluate Print Loop
Can include your project on Classpath
Quick iterative testing
Rapid exploration and learning
Better than a debugger println("Hello, World!") public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Originated by Martin Odersky at EPFL, Switzerland, in 2001
Previous PhD student of Niklaus Wirth
First public release in 2003 Can be run directly, like a dynamic language Especially for Java developers
..Ruby Developers
.. Python Developers
..SmallTalk Developers Everything an Object, No primitives
"+" is a method on Int, for example XML Library Closures
Immutables
Every function is a value
Higher-order functions
Nested functions
Currying
Pattern Matching Nested Classes
Classes can be scoped within other classes
Methods/Functions/Packages can also be nested object Lunar extends Baysick {
def main(args:Array[String]) = {
10 PRINT "Welcome to Baysick Lunar Lander v0.9"
20 LET ('dist := 100)
30 LET ('v := 1)
40 LET ('fuel := 1000)
50 LET ('mass := 1000)

60 PRINT "You are drifting towards the moon."

70 PRINT "You must decide how much fuel to burn."
80 PRINT "To accelerate enter a positive number"
90 PRINT "To decelerate a negative"

100 PRINT "Distance " % 'dist % "km, " % "Velocity " % 'v % "km/s, " % "Fuel " % 'fuel
110 INPUT 'burn
120 IF ABS('burn) <= 'fuel THEN 150
130 PRINT "You don't have that much fuel"

140 GOTO 100
150 LET ('v := 'v + 'burn * 10 / ('fuel + 'mass))
160 LET ('fuel := 'fuel - ABS('burn))
170 LET ('dist := 'dist - 'v)
180 IF 'dist > 0 THEN 100
190 PRINT "You have hit the surface"
200 IF 'v < 3 THEN 240
210 PRINT "Hit surface too fast (" % 'v % ")km/s"
220 PRINT "You Crashed!"

230 GOTO 250
240 PRINT "Well done"

250 END

RUN
}
} paycheck for employee "Buck Trends" is salary for 2 weeks minus deductions for {
federal income tax is 25. percent of gross,
state income tax is 5. percent of gross,
insurance premiums are 500. in gross currency,
retirement fund contributions are 10. percent of gross
} Generic classes
Variance annotations
Upper and lower type bounds
Inner classes
Abstract types
Explicitly typed self references
Compound types
Views
Polymorphic methods new Order to sell(200 bondsOf "Sun")
maxUnitPrice 300
using {
(qty, unit) => qty * unit - 500
} class Stack[T] {
var elems: List[T] = Nil
def push(x: T) { elems = x :: elems }
def top: T = elems.head
def pop() { elems = elems.tail }
} class Stack[+A] {
def push[B >: A](elem: B): Stack[B] = new Stack[B] {
override def top: B = elem
override def pop: Stack[B] = Stack.this
override def toString() = elem.toString() + " " +
Stack.this.toString()
}
def top: A = error("no element on stack")
def pop: Stack[A] = error("no element on stack")
override def toString() = ""
} Michael Nash
Software Craftsman, Point2 Technologies
Blog: "Two Cents Worth" Scala
Scalable object/functional language How? Where to begin using Scala?
Unit Testing
Functional/Integration Testing
Web Applications
Lift
Blends well into existing Java projects #!/bin/sh
exec scala "$0" "$@"
!# // Say hello to the first argument
println("Hello, "+ args(0) +"!") Productivity: Like a scripting language, but with type safety and speed
Easier Concurrency
Efficient Development
Superior Maintainability def act() {
loop {
react {
case (name: String, actor: Actor) =>
actor ! getIp(name)
case msg =>
println("Unhandled message " + msg)
}
}
} Lightweight concurrency
Based on Erlang-style Actors
Message-passing def simplifyTop(expr: Expr): Expr = expr match {
case UnOp("-", UnOp("-", e)) => e
case BinOp("+", e, Number(0)) => e
case _ => expr
} Much more than switch or case statements
Sophisticated pattern matching Optional Parameters
Named Parameters Methods, values, objects
Scoped for visibility in entire package Not corporate-controlled
Rapid evolution
New features Tool Support def rest = <book>
<author>
<first>{firstName}</first>
<last>{lastName}</last>
</author>
</book> Method and Field definitions, partial or complete
Classes can mix in any number of traits class Frog extends Prince with Reptile {... Fully Object Oriented 2.+2 val s: String = "Hello"
val s = "Hello" class Person(val name: String, val rank: String, val serial: Int) "Scala was designed to be both object-oriented and functional. It is a pure object-oriented language in the sense that every value is an object. Objects are defined by classes, which can be composed using mixin composition. Scala is also a functional language in the sense that every function is a value. Functions can be nested, and they can operate on data using pattern matching. "
Martin Odersky Flexible Nesting No more NullPointerExceptions
Some and None are subclasses
Options are comprehensible
getOrElse
foreach
Flexible Syntax Easy to Learn DSLs from(playlistElements, songs)((ple, s) =>
where(ple.playlistId === id and ple.songId === s.id)
select(s)
orderBy(ple.songNumber asc) Where? class Person(val name: String, val rank: String, val serial: Int)

public class Person {
private final String name;
private final String rank;
private final Integer serial;

public Person(String name, String rank, Integer serial) {
this.name = name;
this.rank = rank;
this.serial = serial;
}

public String getName() {
return name;
}

public String getRank() {
return rank;
}

public Integer getSerial() {
return serial;
}
}
"I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy."

- James Strachan, creator of Groovy "Scala, it must be stated, is the current heir apparent to the Java throne."

- Charles Nutter, creator of JRuby "Which Programming Language would you use *now* on top of JVM, except Java?"
"Scala."
- James Gosling, creator of Java "
Full transcript